SlideShare uma empresa Scribd logo
1 de 20
Baixar para ler offline
Introdução ao Byteman
Filippe Spolti
Software Engineer - Red Hat
Resolvendo o problema
RULE setRequestsRecovery
CLASS org.jbpm.process.core.timer.impl.QuartzSchedulerService
METHOD internalSchedule
AT WRITE $jobq
IF TRUE
DO
traceln("[BYTEMAN] Current Value for requestsRecovery: " + $jobq.requestsRecovery() +
" ---------- UPDATING");
$jobq.setRequestsRecovery(true);
traceln("[BYTEMAN] New value for requestsRecovery: " + $jobq.requestsRecovery());
ENDRULE
Primeiros Passos
• Como Ativar o Byteman?
• -javaagent:/$BYTEMAN_HOME/lib/byteman.jar=script:$BYTEMAN_HOME/scripts/MyCo
olScript.btm
• sys - Adiciona o byteman ao System classloader.
• boot - Adiciona o byteman ao bootstrap classloader.
• Load/Unload Byteman em Runtime
• bminstall.sh - Cuidado!
• bmsubmit.sh - Load/Unload de Scripts Byteman.
• Integrações
• Principais framework de testes: Junit e TestNG.
• Maven/ant (Annotations).
• Validando o script
• bmcheck.sh
ECA - Event Conditions Action
• Where (onde)
• CLASS java.lang.Thread
• METHOD start()
• AT ENTRY
• Whether (se)
• IF true
• What (Qual)
• DO traceln("*** Hello TDC POA ***")
Esqueleto do Script Byteman
RULE @X regra feliz
COMPILE|NOCOMPILE (Opcional)
CLASS|INTERFACE br.com.tdcpoa.MinhaClasseLegal
METHOD NaoMeModifique (Para construtores <init>)
HELPER br.com.tdcpoa.MeuAjudanteNota10 (Opcional)
AT WRITE $objetoA (Opcional)
BIND nome:type = valor (Opcional)
feliz:boolean = $objetoA.Feliz();
IF feliz == true
DO //faça algo legal
minhaOperacaoBuiltInParaImprimir(“Feliz“);
ENDRULE - Fim da definição da regra
Especificadores de Localização
AT ENTRY AFTER INVOKE [ type .] method [ ( argtypes ) ][count | ALL ]
AT EXIT AT SYNCHRONIZE [count | ALL ]
AT LINE number AFTER SYNCHRONIZE [count | ALL ]
AT READ [type .] field [count | ALL ] AT THROW [count | ALL ]
AT READ $var-or-idx [count | ALL ] AT EXCEPTION EXIT
AFTER READ [ type .] field [count | ALL ]
AFTER READ $var-or-idx [count | ALL ]
AT WRITE [ type .] field [count | ALL ]
AT WRITE $var-or-idx [count | ALL ]
AFTER WRITE [ type .] field [count | ALL ]
AFTER WRITE $var-or-idx [count | ALL ]
AT INVOKE [ type .] method [ ( argtypes ) ] [count | ALL ]
O que é um Helper?
• Auxiliar
• Helper.java
• Subdivido em três categorias:
• coordenação de threads
• Gerenciamento do ciclo de vida das regras
• Debug e Tracing
import org.jboss.byteman.rule.helper.Helper;
public class MeuAjudanteNota10 extends Helper {
public void printHello(){
System.out.println(“Hello TDC POA);
}
}
Expressões de Referência
$!, $^, $#, $*, $@, $CLASS e $METHOD
$0, $1, $x, $this
CLASS ^javax.naming.InitialContext
Operadores
OR (||), LE (< =), NE (!=) TIMES (*) MINUS (-)
AND (&&), LT (<) GE (>=) DIVIDE (/) MOD (%)
NOT (!), EQ (==), GT (>) PLUS (+)
Principais Expressões
Compilar ou Interpretar as regras?
● Interpretadas
● Vale a pena?
● Quando usar regras compiladas?
● org.jboss.byteman.compile.to.bytecode
ClassNotFound?
● IMPORTS
● JBoss Modules
● OSGI e JigSaw (java 9)
BMunit
Código Java
@RunWith(org.jboss.byteman.contrib.bmunit.BMUnitRunner.class)
@BMUnitConfig(loadDirectory="target/test-classes")
@BMScript(value="check.btm")
public class MavenBMUnitTest {
@Test
...
}
A regra:
RULE check head
CLASS WebWriter
METHOD makeHeader
AT EXIT
BIND result = $builder.toString()
IF (NOT result.contains("<HEAD>") || NOT result.contains("</HEAD>"))
DO
THROW new RuntimeException("Header Inválido, Byteman got you. :)");
ENDRULE
Verificando Regras
• Sempre verifique
• Livre de erros e warnings
• bmcheck
• bmcheck.sh -p br.com.tdcpoa -cp .
../../src/test/resources/check.btm
• maven
• configurar plugin byteman-rulecheck-maven-plugin
Ativando o Byteman no WildFly 10!
• Arquivos standalone.conf e domain.conf
if [ "x$JBOSS_MODULES_SYSTEM_PKGS" = "x" ]; then
JBOSS_MODULES_SYSTEM_PKGS="org.jboss.byteman"
fi
Modo Standalone:
JAVA_OPTS="$JAVA_OPTS
-javaagent:$BYTEMAN_HOME/lib/byteman.jar=script:/dados/presentations/byteman/demo/byteman-web-app/src/resources/th
read.btm,boot:$BYTEMAN_HOME/lib/byteman.jar,boot:/dados/presentations/byteman/demo/byteman-helper/target/byteman-
helper-1.0-SNAPSHOT.jar -Dorg.jboss.byteman.transform.all"
Domain:
<jvm-options>
<option
value="-javaagent:/${jboss.home.dir}/byteman/lib/byteman.jar=script:${jboss.home.dir}/byteman/scripts/org.jboss.re
moting3.EndpointImpl.btm,boot:${jboss.home.dir}/byteman/lib/byteman.jar"/>
<option value="-Dorg.jboss.byteman.transform.all=true"/>
</jvm-options>
Trabalhando com Regras em Runtime
● Instalando o byteman em uma JVM em execução:
> bminstall.sh 13101
> bminstall.sh -b -Dorg.jboss.byteman.transform.all
$JBOSS_HOME/jboss-modules.jar
● Carregando regras em runtime:
> bmsubmit.sh -l thread.btm
Descarregando regras:
> bmsubmit.sh -u thread.btm
Opções disponíveis do agente java
script:scriptfile
resourcescript:scriptfile
listener:boolean
port:portnum
address:host
manager:classname
modules:classname
sys:jarfile
boot:jarfile
policy:boolean
prop:name=value
Opções extra de configuração
Algumas configurações avançadas
• org.jboss.byteman.compileToBytecode
• org.jboss.byteman.dump.generated.classes
• org.jboss.byteman.dump.generated.classes.directory
• org.jboss.byteman.dump.generated.classes.intermediate
• org.jboss.byteman.debug
• org.jboss.byteman.transform.all
• org.jboss.byteman.skip.overriding.rules
• org.jboss.byteman.allow.config.updates
• org.jboss.byteman.sysprops.strict
Exemplo de Configuração
JAVA_OPTS="$JAVA_OPTS
-javaagent:$BYTEMAN_HOME/lib/byteman.jar=script:/dados/presentations/byteman/demo/byteman-web-app/s
rc/resources/rule.btm,boot:$BYTEMAN_HOME/lib/byteman.jar,boot:/dados/presentations/byteman/demo/byte
man-helper/target/byteman-helper-1.0-SNAPSHOT.jar -Dorg.jboss.byteman.transform.all"
Detalhando:
● -javaagent:/$BYTEMAN_HOME/lib/byteman.jar
○ É responsável por ativar o Byteman, Qualquer coisa depois do ‘=’ são as configurações do Byteman
separadas por vírgula.
● script:$BYTEMAN_HOME/scripts/script.btm
○ /dados/presentations/byteman/demo/byteman-web-app/src/resources/thread.btm
● boot:$BYTEMAN_HOME/lib/byteman.jar
○ diz ao Byteman que ele deve ser carregado no classloader bootstrap para acessar até classes da JVM.
● boot:$BYTEMAN_HOME/lib/byteman-helpers.jar
○ Define o helper no classloader bootstrap.
QuickStarts e tutoriais
● https://developer.jboss.org/wiki/FaultInjectionTestingWithByteman
● $BYTEMAN_HOME/contrib
● https://developer.jboss.org/wiki/BMUnitUsingBytemanWithJUnitOrTestNGFr
omMavenAndAnt
● https://developer.jboss.org/wiki/CheckingYourBytemanRuleScriptsUnderMav
en
● https://developer.jboss.org/wiki/FaultInjectionTestingWithByteman
● https://developer.jboss.org/wiki/BMUnitUsingBytemanWithJUnitOrTestNGFr
omMavenAndAnt#how_do_i_inject_trace_into_junit_tests
Demonstração
That’s it Folks
Obrigado!
http://byteman.jboss.org/
https://github.com/bytemanproject/byteman
IRC - Servidor: freenode - Canal: #byteman
https://www.gitbook.com/book/jboss-books/byteman-guia-do-programador/details
https://www.gitbook.com/@jboss-books/
https://github.com/jbug-brasil/byteman-repo
Telegram - Grupo JBug Brasil
IRC - Servidor: freenode - Canal: #jbug-brasil

Mais conteúdo relacionado

Mais procurados

You Don't Know Query - WordCamp Portland 2011
You Don't Know Query - WordCamp Portland 2011You Don't Know Query - WordCamp Portland 2011
You Don't Know Query - WordCamp Portland 2011andrewnacin
 
MySQL in Go - Golang NE July 2015
MySQL in Go - Golang NE July 2015MySQL in Go - Golang NE July 2015
MySQL in Go - Golang NE July 2015Mark Hemmings
 
WordPress Security - ওয়ার্ডপ্রেসের সিকিউরিটি
WordPress Security - ওয়ার্ডপ্রেসের সিকিউরিটিWordPress Security - ওয়ার্ডপ্রেসের সিকিউরিটি
WordPress Security - ওয়ার্ডপ্রেসের সিকিউরিটিFaysal Shahi
 
Ansible tips & tricks
Ansible tips & tricksAnsible tips & tricks
Ansible tips & tricksbcoca
 
Hd insight programming
Hd insight programmingHd insight programming
Hd insight programmingCasear Chu
 
Working with databases in Perl
Working with databases in PerlWorking with databases in Perl
Working with databases in PerlLaurent Dami
 
Europython 2011 - Playing tasks with Django & Celery
Europython 2011 - Playing tasks with Django & CeleryEuropython 2011 - Playing tasks with Django & Celery
Europython 2011 - Playing tasks with Django & CeleryMauro Rocco
 
Smolder @Silex
Smolder @SilexSmolder @Silex
Smolder @SilexJeen Lee
 
Power shell examples_v4
Power shell examples_v4Power shell examples_v4
Power shell examples_v4JoeDinaso
 
Django Celery - A distributed task queue
Django Celery - A distributed task queueDjango Celery - A distributed task queue
Django Celery - A distributed task queueAlex Eftimie
 
Django - 次の一歩 gumiStudy#3
Django - 次の一歩 gumiStudy#3Django - 次の一歩 gumiStudy#3
Django - 次の一歩 gumiStudy#3makoto tsuyuki
 
Asynchronous I/O in PHP
Asynchronous I/O in PHPAsynchronous I/O in PHP
Asynchronous I/O in PHPThomas Weinert
 
Perl Bag of Tricks - Baltimore Perl mongers
Perl Bag of Tricks  -  Baltimore Perl mongersPerl Bag of Tricks  -  Baltimore Perl mongers
Perl Bag of Tricks - Baltimore Perl mongersbrian d foy
 

Mais procurados (20)

You Don't Know Query - WordCamp Portland 2011
You Don't Know Query - WordCamp Portland 2011You Don't Know Query - WordCamp Portland 2011
You Don't Know Query - WordCamp Portland 2011
 
MySQL in Go - Golang NE July 2015
MySQL in Go - Golang NE July 2015MySQL in Go - Golang NE July 2015
MySQL in Go - Golang NE July 2015
 
dotCloud and go
dotCloud and godotCloud and go
dotCloud and go
 
WordPress Security - ওয়ার্ডপ্রেসের সিকিউরিটি
WordPress Security - ওয়ার্ডপ্রেসের সিকিউরিটিWordPress Security - ওয়ার্ডপ্রেসের সিকিউরিটি
WordPress Security - ওয়ার্ডপ্রেসের সিকিউরিটি
 
Ansible tips & tricks
Ansible tips & tricksAnsible tips & tricks
Ansible tips & tricks
 
Hd insight programming
Hd insight programmingHd insight programming
Hd insight programming
 
Fatc
FatcFatc
Fatc
 
Working with databases in Perl
Working with databases in PerlWorking with databases in Perl
Working with databases in Perl
 
Europython 2011 - Playing tasks with Django & Celery
Europython 2011 - Playing tasks with Django & CeleryEuropython 2011 - Playing tasks with Django & Celery
Europython 2011 - Playing tasks with Django & Celery
 
Unit Testing Lots of Perl
Unit Testing Lots of PerlUnit Testing Lots of Perl
Unit Testing Lots of Perl
 
Puppet Camp 2012
Puppet Camp 2012Puppet Camp 2012
Puppet Camp 2012
 
Bake by cake php2.0
Bake by cake php2.0Bake by cake php2.0
Bake by cake php2.0
 
Smolder @Silex
Smolder @SilexSmolder @Silex
Smolder @Silex
 
Effective Benchmarks
Effective BenchmarksEffective Benchmarks
Effective Benchmarks
 
Go database/sql
Go database/sqlGo database/sql
Go database/sql
 
Power shell examples_v4
Power shell examples_v4Power shell examples_v4
Power shell examples_v4
 
Django Celery - A distributed task queue
Django Celery - A distributed task queueDjango Celery - A distributed task queue
Django Celery - A distributed task queue
 
Django - 次の一歩 gumiStudy#3
Django - 次の一歩 gumiStudy#3Django - 次の一歩 gumiStudy#3
Django - 次の一歩 gumiStudy#3
 
Asynchronous I/O in PHP
Asynchronous I/O in PHPAsynchronous I/O in PHP
Asynchronous I/O in PHP
 
Perl Bag of Tricks - Baltimore Perl mongers
Perl Bag of Tricks  -  Baltimore Perl mongersPerl Bag of Tricks  -  Baltimore Perl mongers
Perl Bag of Tricks - Baltimore Perl mongers
 

Destaque

Dugotrajni tangzhong-hljeb
Dugotrajni tangzhong-hljebDugotrajni tangzhong-hljeb
Dugotrajni tangzhong-hljebBOLDIZ
 
Império romano 1
Império romano 1Império romano 1
Império romano 1Jorgelgl
 
Meu automóvel
Meu automóvelMeu automóvel
Meu automóvelCarlaMPB
 
DESENVOLVIMENTO DE PRODUTOS E OPERAÇÕES - ORGANIZAÇÕES VISÃO MACRO
DESENVOLVIMENTO DE PRODUTOS E OPERAÇÕES - ORGANIZAÇÕES VISÃO MACRODESENVOLVIMENTO DE PRODUTOS E OPERAÇÕES - ORGANIZAÇÕES VISÃO MACRO
DESENVOLVIMENTO DE PRODUTOS E OPERAÇÕES - ORGANIZAÇÕES VISÃO MACROWeNova Consulting
 
Maturidade e crescimento espiritual
Maturidade e crescimento espiritualMaturidade e crescimento espiritual
Maturidade e crescimento espiritualmgno42
 
Administração de Operações - PCP
Administração de Operações - PCPAdministração de Operações - PCP
Administração de Operações - PCPWeNova Consulting
 
Administração de Operações - Introdução
Administração de Operações - IntroduçãoAdministração de Operações - Introdução
Administração de Operações - IntroduçãoWeNova Consulting
 
Emailsradio lovor
Emailsradio lovorEmailsradio lovor
Emailsradio lovorradio2203
 
Logística Empresarial Estoques
Logística Empresarial EstoquesLogística Empresarial Estoques
Logística Empresarial EstoquesWeNova Consulting
 
Logística Empresarial Cadeia De Suprimentos
Logística Empresarial Cadeia De SuprimentosLogística Empresarial Cadeia De Suprimentos
Logística Empresarial Cadeia De SuprimentosWeNova Consulting
 
Capilaroscopia 2007
Capilaroscopia 2007Capilaroscopia 2007
Capilaroscopia 2007Jose Bruno
 
Google Drive
Google DriveGoogle Drive
Google DriveMana_
 

Destaque (17)

Dugotrajni tangzhong-hljeb
Dugotrajni tangzhong-hljebDugotrajni tangzhong-hljeb
Dugotrajni tangzhong-hljeb
 
Império romano 1
Império romano 1Império romano 1
Império romano 1
 
Cacau e babosa
Cacau e babosaCacau e babosa
Cacau e babosa
 
Meu automóvel
Meu automóvelMeu automóvel
Meu automóvel
 
Apresentação1
Apresentação1Apresentação1
Apresentação1
 
DESENVOLVIMENTO DE PRODUTOS E OPERAÇÕES - ORGANIZAÇÕES VISÃO MACRO
DESENVOLVIMENTO DE PRODUTOS E OPERAÇÕES - ORGANIZAÇÕES VISÃO MACRODESENVOLVIMENTO DE PRODUTOS E OPERAÇÕES - ORGANIZAÇÕES VISÃO MACRO
DESENVOLVIMENTO DE PRODUTOS E OPERAÇÕES - ORGANIZAÇÕES VISÃO MACRO
 
Eva peron
Eva  peronEva  peron
Eva peron
 
MIPS Pipeline
MIPS Pipeline MIPS Pipeline
MIPS Pipeline
 
Maturidade e crescimento espiritual
Maturidade e crescimento espiritualMaturidade e crescimento espiritual
Maturidade e crescimento espiritual
 
Administração de Operações - PCP
Administração de Operações - PCPAdministração de Operações - PCP
Administração de Operações - PCP
 
Administração de Operações - Introdução
Administração de Operações - IntroduçãoAdministração de Operações - Introdução
Administração de Operações - Introdução
 
Brigada de incendio
Brigada de incendioBrigada de incendio
Brigada de incendio
 
Emailsradio lovor
Emailsradio lovorEmailsradio lovor
Emailsradio lovor
 
Logística Empresarial Estoques
Logística Empresarial EstoquesLogística Empresarial Estoques
Logística Empresarial Estoques
 
Logística Empresarial Cadeia De Suprimentos
Logística Empresarial Cadeia De SuprimentosLogística Empresarial Cadeia De Suprimentos
Logística Empresarial Cadeia De Suprimentos
 
Capilaroscopia 2007
Capilaroscopia 2007Capilaroscopia 2007
Capilaroscopia 2007
 
Google Drive
Google DriveGoogle Drive
Google Drive
 

Semelhante a Introduction to Byteman

Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Michelangelo van Dam
 
Workshop quality assurance for php projects - phpbelfast
Workshop quality assurance for php projects - phpbelfastWorkshop quality assurance for php projects - phpbelfast
Workshop quality assurance for php projects - phpbelfastMichelangelo van Dam
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Michelangelo van Dam
 
Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013Michelangelo van Dam
 
Bye bye $GLOBALS['TYPO3_DB']
Bye bye $GLOBALS['TYPO3_DB']Bye bye $GLOBALS['TYPO3_DB']
Bye bye $GLOBALS['TYPO3_DB']Jan Helke
 
Php Unit With Zend Framework Zendcon09
Php Unit With Zend Framework   Zendcon09Php Unit With Zend Framework   Zendcon09
Php Unit With Zend Framework Zendcon09Michelangelo van Dam
 
Load Testing with PHP and RedLine13
Load Testing with PHP and RedLine13Load Testing with PHP and RedLine13
Load Testing with PHP and RedLine13Jason Lotito
 
Custom deployments with sbt-native-packager
Custom deployments with sbt-native-packagerCustom deployments with sbt-native-packager
Custom deployments with sbt-native-packagerGaryCoady
 
AppSec USA 2015: Customizing Burp Suite
AppSec USA 2015: Customizing Burp SuiteAppSec USA 2015: Customizing Burp Suite
AppSec USA 2015: Customizing Burp SuiteAugust Detlefsen
 
Building Testable PHP Applications
Building Testable PHP ApplicationsBuilding Testable PHP Applications
Building Testable PHP Applicationschartjes
 
Apache Calcite Tutorial - BOSS 21
Apache Calcite Tutorial - BOSS 21Apache Calcite Tutorial - BOSS 21
Apache Calcite Tutorial - BOSS 21Stamatis Zampetakis
 
PHPUnit best practices presentation
PHPUnit best practices presentationPHPUnit best practices presentation
PHPUnit best practices presentationThanh Robi
 
Charla EHU Noviembre 2014 - Desarrollo Web
Charla EHU Noviembre 2014 - Desarrollo WebCharla EHU Noviembre 2014 - Desarrollo Web
Charla EHU Noviembre 2014 - Desarrollo WebMikel Torres Ugarte
 
PerlApp2Postgresql (2)
PerlApp2Postgresql (2)PerlApp2Postgresql (2)
PerlApp2Postgresql (2)Jerome Eteve
 
Testing Your Automation Code (Vagrant Version)
Testing Your Automation Code (Vagrant Version)Testing Your Automation Code (Vagrant Version)
Testing Your Automation Code (Vagrant Version)Mischa Taylor
 
Windows Server 2008 (PowerShell Scripting Uygulamaları)
Windows Server 2008 (PowerShell Scripting Uygulamaları)Windows Server 2008 (PowerShell Scripting Uygulamaları)
Windows Server 2008 (PowerShell Scripting Uygulamaları)ÇözümPARK
 
Testing ASP.NET - Progressive.NET
Testing ASP.NET - Progressive.NETTesting ASP.NET - Progressive.NET
Testing ASP.NET - Progressive.NETBen Hall
 
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak   CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak PROIDEA
 

Semelhante a Introduction to Byteman (20)

Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012
 
Workshop quality assurance for php projects - phpbelfast
Workshop quality assurance for php projects - phpbelfastWorkshop quality assurance for php projects - phpbelfast
Workshop quality assurance for php projects - phpbelfast
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12
 
Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013
 
Bye bye $GLOBALS['TYPO3_DB']
Bye bye $GLOBALS['TYPO3_DB']Bye bye $GLOBALS['TYPO3_DB']
Bye bye $GLOBALS['TYPO3_DB']
 
Django quickstart
Django quickstartDjango quickstart
Django quickstart
 
Php Unit With Zend Framework Zendcon09
Php Unit With Zend Framework   Zendcon09Php Unit With Zend Framework   Zendcon09
Php Unit With Zend Framework Zendcon09
 
Load Testing with PHP and RedLine13
Load Testing with PHP and RedLine13Load Testing with PHP and RedLine13
Load Testing with PHP and RedLine13
 
Custom deployments with sbt-native-packager
Custom deployments with sbt-native-packagerCustom deployments with sbt-native-packager
Custom deployments with sbt-native-packager
 
AppSec USA 2015: Customizing Burp Suite
AppSec USA 2015: Customizing Burp SuiteAppSec USA 2015: Customizing Burp Suite
AppSec USA 2015: Customizing Burp Suite
 
Building Testable PHP Applications
Building Testable PHP ApplicationsBuilding Testable PHP Applications
Building Testable PHP Applications
 
Apache Calcite Tutorial - BOSS 21
Apache Calcite Tutorial - BOSS 21Apache Calcite Tutorial - BOSS 21
Apache Calcite Tutorial - BOSS 21
 
QA for PHP projects
QA for PHP projectsQA for PHP projects
QA for PHP projects
 
PHPUnit best practices presentation
PHPUnit best practices presentationPHPUnit best practices presentation
PHPUnit best practices presentation
 
Charla EHU Noviembre 2014 - Desarrollo Web
Charla EHU Noviembre 2014 - Desarrollo WebCharla EHU Noviembre 2014 - Desarrollo Web
Charla EHU Noviembre 2014 - Desarrollo Web
 
PerlApp2Postgresql (2)
PerlApp2Postgresql (2)PerlApp2Postgresql (2)
PerlApp2Postgresql (2)
 
Testing Your Automation Code (Vagrant Version)
Testing Your Automation Code (Vagrant Version)Testing Your Automation Code (Vagrant Version)
Testing Your Automation Code (Vagrant Version)
 
Windows Server 2008 (PowerShell Scripting Uygulamaları)
Windows Server 2008 (PowerShell Scripting Uygulamaları)Windows Server 2008 (PowerShell Scripting Uygulamaları)
Windows Server 2008 (PowerShell Scripting Uygulamaları)
 
Testing ASP.NET - Progressive.NET
Testing ASP.NET - Progressive.NETTesting ASP.NET - Progressive.NET
Testing ASP.NET - Progressive.NET
 
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak   CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
 

Introduction to Byteman

  • 1. Introdução ao Byteman Filippe Spolti Software Engineer - Red Hat
  • 2.
  • 3. Resolvendo o problema RULE setRequestsRecovery CLASS org.jbpm.process.core.timer.impl.QuartzSchedulerService METHOD internalSchedule AT WRITE $jobq IF TRUE DO traceln("[BYTEMAN] Current Value for requestsRecovery: " + $jobq.requestsRecovery() + " ---------- UPDATING"); $jobq.setRequestsRecovery(true); traceln("[BYTEMAN] New value for requestsRecovery: " + $jobq.requestsRecovery()); ENDRULE
  • 4. Primeiros Passos • Como Ativar o Byteman? • -javaagent:/$BYTEMAN_HOME/lib/byteman.jar=script:$BYTEMAN_HOME/scripts/MyCo olScript.btm • sys - Adiciona o byteman ao System classloader. • boot - Adiciona o byteman ao bootstrap classloader. • Load/Unload Byteman em Runtime • bminstall.sh - Cuidado! • bmsubmit.sh - Load/Unload de Scripts Byteman. • Integrações • Principais framework de testes: Junit e TestNG. • Maven/ant (Annotations). • Validando o script • bmcheck.sh
  • 5. ECA - Event Conditions Action • Where (onde) • CLASS java.lang.Thread • METHOD start() • AT ENTRY • Whether (se) • IF true • What (Qual) • DO traceln("*** Hello TDC POA ***")
  • 6. Esqueleto do Script Byteman RULE @X regra feliz COMPILE|NOCOMPILE (Opcional) CLASS|INTERFACE br.com.tdcpoa.MinhaClasseLegal METHOD NaoMeModifique (Para construtores <init>) HELPER br.com.tdcpoa.MeuAjudanteNota10 (Opcional) AT WRITE $objetoA (Opcional) BIND nome:type = valor (Opcional) feliz:boolean = $objetoA.Feliz(); IF feliz == true DO //faça algo legal minhaOperacaoBuiltInParaImprimir(“Feliz“); ENDRULE - Fim da definição da regra
  • 7. Especificadores de Localização AT ENTRY AFTER INVOKE [ type .] method [ ( argtypes ) ][count | ALL ] AT EXIT AT SYNCHRONIZE [count | ALL ] AT LINE number AFTER SYNCHRONIZE [count | ALL ] AT READ [type .] field [count | ALL ] AT THROW [count | ALL ] AT READ $var-or-idx [count | ALL ] AT EXCEPTION EXIT AFTER READ [ type .] field [count | ALL ] AFTER READ $var-or-idx [count | ALL ] AT WRITE [ type .] field [count | ALL ] AT WRITE $var-or-idx [count | ALL ] AFTER WRITE [ type .] field [count | ALL ] AFTER WRITE $var-or-idx [count | ALL ] AT INVOKE [ type .] method [ ( argtypes ) ] [count | ALL ]
  • 8. O que é um Helper? • Auxiliar • Helper.java • Subdivido em três categorias: • coordenação de threads • Gerenciamento do ciclo de vida das regras • Debug e Tracing import org.jboss.byteman.rule.helper.Helper; public class MeuAjudanteNota10 extends Helper { public void printHello(){ System.out.println(“Hello TDC POA); } }
  • 9. Expressões de Referência $!, $^, $#, $*, $@, $CLASS e $METHOD $0, $1, $x, $this CLASS ^javax.naming.InitialContext Operadores OR (||), LE (< =), NE (!=) TIMES (*) MINUS (-) AND (&&), LT (<) GE (>=) DIVIDE (/) MOD (%) NOT (!), EQ (==), GT (>) PLUS (+) Principais Expressões
  • 10. Compilar ou Interpretar as regras? ● Interpretadas ● Vale a pena? ● Quando usar regras compiladas? ● org.jboss.byteman.compile.to.bytecode ClassNotFound? ● IMPORTS ● JBoss Modules ● OSGI e JigSaw (java 9)
  • 11. BMunit Código Java @RunWith(org.jboss.byteman.contrib.bmunit.BMUnitRunner.class) @BMUnitConfig(loadDirectory="target/test-classes") @BMScript(value="check.btm") public class MavenBMUnitTest { @Test ... } A regra: RULE check head CLASS WebWriter METHOD makeHeader AT EXIT BIND result = $builder.toString() IF (NOT result.contains("<HEAD>") || NOT result.contains("</HEAD>")) DO THROW new RuntimeException("Header Inválido, Byteman got you. :)"); ENDRULE
  • 12. Verificando Regras • Sempre verifique • Livre de erros e warnings • bmcheck • bmcheck.sh -p br.com.tdcpoa -cp . ../../src/test/resources/check.btm • maven • configurar plugin byteman-rulecheck-maven-plugin
  • 13. Ativando o Byteman no WildFly 10! • Arquivos standalone.conf e domain.conf if [ "x$JBOSS_MODULES_SYSTEM_PKGS" = "x" ]; then JBOSS_MODULES_SYSTEM_PKGS="org.jboss.byteman" fi Modo Standalone: JAVA_OPTS="$JAVA_OPTS -javaagent:$BYTEMAN_HOME/lib/byteman.jar=script:/dados/presentations/byteman/demo/byteman-web-app/src/resources/th read.btm,boot:$BYTEMAN_HOME/lib/byteman.jar,boot:/dados/presentations/byteman/demo/byteman-helper/target/byteman- helper-1.0-SNAPSHOT.jar -Dorg.jboss.byteman.transform.all" Domain: <jvm-options> <option value="-javaagent:/${jboss.home.dir}/byteman/lib/byteman.jar=script:${jboss.home.dir}/byteman/scripts/org.jboss.re moting3.EndpointImpl.btm,boot:${jboss.home.dir}/byteman/lib/byteman.jar"/> <option value="-Dorg.jboss.byteman.transform.all=true"/> </jvm-options>
  • 14. Trabalhando com Regras em Runtime ● Instalando o byteman em uma JVM em execução: > bminstall.sh 13101 > bminstall.sh -b -Dorg.jboss.byteman.transform.all $JBOSS_HOME/jboss-modules.jar ● Carregando regras em runtime: > bmsubmit.sh -l thread.btm Descarregando regras: > bmsubmit.sh -u thread.btm
  • 15. Opções disponíveis do agente java script:scriptfile resourcescript:scriptfile listener:boolean port:portnum address:host manager:classname modules:classname sys:jarfile boot:jarfile policy:boolean prop:name=value
  • 16. Opções extra de configuração Algumas configurações avançadas • org.jboss.byteman.compileToBytecode • org.jboss.byteman.dump.generated.classes • org.jboss.byteman.dump.generated.classes.directory • org.jboss.byteman.dump.generated.classes.intermediate • org.jboss.byteman.debug • org.jboss.byteman.transform.all • org.jboss.byteman.skip.overriding.rules • org.jboss.byteman.allow.config.updates • org.jboss.byteman.sysprops.strict
  • 17. Exemplo de Configuração JAVA_OPTS="$JAVA_OPTS -javaagent:$BYTEMAN_HOME/lib/byteman.jar=script:/dados/presentations/byteman/demo/byteman-web-app/s rc/resources/rule.btm,boot:$BYTEMAN_HOME/lib/byteman.jar,boot:/dados/presentations/byteman/demo/byte man-helper/target/byteman-helper-1.0-SNAPSHOT.jar -Dorg.jboss.byteman.transform.all" Detalhando: ● -javaagent:/$BYTEMAN_HOME/lib/byteman.jar ○ É responsável por ativar o Byteman, Qualquer coisa depois do ‘=’ são as configurações do Byteman separadas por vírgula. ● script:$BYTEMAN_HOME/scripts/script.btm ○ /dados/presentations/byteman/demo/byteman-web-app/src/resources/thread.btm ● boot:$BYTEMAN_HOME/lib/byteman.jar ○ diz ao Byteman que ele deve ser carregado no classloader bootstrap para acessar até classes da JVM. ● boot:$BYTEMAN_HOME/lib/byteman-helpers.jar ○ Define o helper no classloader bootstrap.
  • 18. QuickStarts e tutoriais ● https://developer.jboss.org/wiki/FaultInjectionTestingWithByteman ● $BYTEMAN_HOME/contrib ● https://developer.jboss.org/wiki/BMUnitUsingBytemanWithJUnitOrTestNGFr omMavenAndAnt ● https://developer.jboss.org/wiki/CheckingYourBytemanRuleScriptsUnderMav en ● https://developer.jboss.org/wiki/FaultInjectionTestingWithByteman ● https://developer.jboss.org/wiki/BMUnitUsingBytemanWithJUnitOrTestNGFr omMavenAndAnt#how_do_i_inject_trace_into_junit_tests
  • 20. That’s it Folks Obrigado! http://byteman.jboss.org/ https://github.com/bytemanproject/byteman IRC - Servidor: freenode - Canal: #byteman https://www.gitbook.com/book/jboss-books/byteman-guia-do-programador/details https://www.gitbook.com/@jboss-books/ https://github.com/jbug-brasil/byteman-repo Telegram - Grupo JBug Brasil IRC - Servidor: freenode - Canal: #jbug-brasil