Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Weaver: Ill-Behaved Microservice Emulator

DZone's Guide to

Weaver: Ill-Behaved Microservice Emulator

The author explains the utility Weaver, his open-source, ill-behaved microservice emulator that's used for testing purposes.

· Performance Zone
Free Resource

Evolve your approach to Application Performance Monitoring by adopting five best practices that are outlined and explored in this e-book, brought to you in partnership with BMC.

Weaver is an open-source, ill-behaved microservice emulator for testing purposes. Microservices are very popular nowadays, and even if you don’t do microservices, you still might be developing some code that communicates with the outer world via HTTP.

There are plenty of opportunities where you might need to quickly set up an HTTP-based service, such as when you want to figure out how your service would integrate in a complex pipeline but you don’t want or cannot setup a testing pipeline; when you want to emulate a negative testing scenario; or when you want to prepare a mixture of correct services with a black sheep among them.

Why would you use Weaver and not implement and start your own testing service when it's so easy with so many libraries out there? Because Weaver allows you to easily configure a mixture of various behaviours by supplying various workers to process requests. For example, when you want to have 100 threads processing your requests, of which 99 would behave correctly and only one would cause a very long delay, or when you want a service that is capable of handling only a given number of requests per second, Weaver offers you a set of predefined behaviors (workers) that you can choose and mix as you want. You can also easily provide your own behaviors. Under the hood, it uses one of the available libraries, Vert.x.

The value added is in the fact that instead of dealing with the lower-level API of Vert.x (or any other library), you can just define the behavior that you need or easily develop your own worker. For example, a worker that emulates processing time looks like this:

  public void work(final RoutingContext context) throws Exception {

     try {
        Thread.sleep(delay);
     } catch (InterruptedException e) {
        // nop
     }

     super.work(context);
  }

Weaver can be used as a standalone command line utility (you can download binaries directly on GitHub) or you can use it through its API as a Maven dependency. For the command line approach, you just provide a configuration file with lines in the following format:

<count>x <worker class>=[<attribute1>:<value1>, ..., <attributeN>:<valueN>]

When you want to emulate a service that takes five milliseconds to process a request running in 100 threads, you would create a configuration file (i.e., delay.cfg) like this...

100x DelayWorker=delay:5

...and simply start Weaver as follows:

$ bin/weaver.sh -c projects/delay.cfg

To see what workers are available, have a look on GitHub in the org.perfcake.examples.weaver.worker package. I originally created Weaver as a utility to be able to demonstrate and detect various flaws of microservices with the performance testing tool PerfCake. In the end, I realized that it can be used in many other cases since it is very flexible. Any pull requests are highly appreciated. I hope you enjoy Weaver and find it useful!

Evolve your approach to Application Performance Monitoring by adopting five best practices that are outlined and explored in this e-book, brought to you in partnership with BMC.

Topics:
performance ,weaver ,emulators ,microservices

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}