DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modern Digital Website Security: Prepare to face any form of malicious web activity and enable your sites to optimally serve your customers.

Containers Trend Report: Explore the current state of containers, containerization strategies, and modernizing architecture.

Low-Code Development: Learn the concepts of low code, features + use cases for professional devs, and the low-code implementation process.

E-Commerce Development Essentials: Considering starting or working on an e-commerce business? Learn how to create a backend that scales.

Related

  • A Data-Driven Approach to Application Modernization
  • Five Key Metaverse Launch Features: Everything You Need to Know
  • Providing Enum Consistency Between Application and Data
  • Non-blocking Database Migrations

Trending

  • Automate JBoss Web Server Deployment With the Red Hat Certified Content Collection for JWS
  • Embeddings and Vector Databases: A Hands-On Guide!
  • Accelerating Insights With Couchbase Columnar
  • How to Write API Documentation: Best Practices and Examples
  1. DZone
  2. Data Engineering
  3. Data
  4. Byteman: Byte Code Manipulation Tool for Logging, Testing, and Fault Injection

Byteman: Byte Code Manipulation Tool for Logging, Testing, and Fault Injection

Using the Byteman tool to log, test and fault inject your code at the ByteCode level in the JVM. With code examples for quick understanding.

Siva Prasad Rao Janapati user avatar by
Siva Prasad Rao Janapati
·
Dec. 21, 16 · Tutorial
Like (7)
Save
Tweet
Share
7.7K Views

Join the DZone community and get the full member experience.

Join For Free

Byteman is a byte code manipulation tool for fault injection, testing, and tracing. The Byteman agent allows you to inject rules into an existing Java application without changing the source code. You can inject the rules during the JVM startup time or into a running application without building and redeploying. We can inject the rules for custom Java classes, private methods, and the JRE libraries as well. Below are some Byteman use cases.

  • Add logging statements for the legacy application.
  • Inject fault scenarios to the application via Junit or TestNG unit test cases.

Now, we will see a simple Java application for which we will add debug statements with Byteman.

Let us write a simple Java application.

package org.smarttechie;   
/*** Class will demonstrate the Byteman* @author Siva**/
public class BytemanDemonstration {
    public static void main(String[] args) {    
        System.out.println("With this class we are demonstrating the byteman"); 
    }
}


Download the latest Byteman distribution here.

Write a Byteman script to inject the debug statements for the above class.

RULE trace main entryCLASS BytemanDemonstration
METHOD mainAT ENTRYIF trueDO 
traceln("entering into main method")
ENDRULE   
RULE trace main exitCLASS BytemanDemonstration
METHOD mainAT EXITIF trueDO 
traceln("exiting the main method")
ENDRULE


Launch the JVM by passing the Byteman agent and the script file path.

java -javaagent:${Byteman_Home}\lib\byteman.jar=script:${SCRIPT_FILE_PATH}\logrules.btm <class_name>


After launching the JVM, you will able to see the log messages coming from the script file.

entering into main method
  With this class 
    we are demonstrating the byteman
    exiting the main method


For further exploration, follow these links.

Fault injection Data Types application

Published at DZone with permission of Siva Prasad Rao Janapati, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • A Data-Driven Approach to Application Modernization
  • Five Key Metaverse Launch Features: Everything You Need to Know
  • Providing Enum Consistency Between Application and Data
  • Non-blocking Database Migrations

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: