Skip to content

Custom query distributors

amikryukov edited this page May 6, 2013 · 2 revisions

#Custom query distributors

To add your custom query distributors you need to do:

  1. Create class which extends class QueryPoolLoadBalancer
package test;
...
public class CustomDistributor<Q, E>  extends com.griddynamics.jagger.invoker.QueryPoolLoadBalancer<Q, E> {
   @Override
    public Iterator<com.griddynamics.jagger.util.Pair<Q, E>> provide() {
        ...
    }
}
  1. Create bean in XML file in one of the subdirectories directory "suite" with this class
    <beans:bean id="customDistributor" class="test.CustomDistributor"/>
  1. Create component "query-distributor" with type "query-distributor-ref" and set attribute "ref" to id of bean
    <scenario ...>
        ...
        <query-distributor xsi:type="query-distributor-ref" ref="customDistributor"/>
    </scenario>

Simple Example

Let's make simple custom Query Distributor.

class
package group.id.distributor;

import com.griddynamics.jagger.invoker.QueryPoolLoadBalancer;
import com.griddynamics.jagger.util.Pair;

import java.util.Iterator;

public class FirstPairDistributer<Q, E> extends QueryPoolLoadBalancer<Q, E> {

    @Override
    public Iterator<Pair<Q, E>> provide() {

        final Q query = queryProvider.iterator().next();
        final E endpoint = endpointProvider.iterator().next();

        return new Iterator<Pair<Q, E>>() {
            @Override
            public boolean hasNext() {
                return true;
            }

            @Override
            public Pair<Q, E> next() {
                return Pair.of(query, endpoint);
            }

            @Override
            public void remove() {
                throw new UnsupportedOperationException("Read only iterator");
            }

            @Override
            public String toString() {
                return "FirstPair iterator";
            }
        };
    }

    @Override
    public String toString() {
        return "FirstPairDistributer";
    }
}
bean
<bean id="first-pair-distributor" class="group.id.distributor.FirstPairDistributer"/>
test-description example
    <beans:import resource="distributor/distributor.conf.xml"/>
    <test-description id="jaggerPageTestWithCustomDistributor" parent="default" calibration="true">
        <scenario xsi:type="scenario-query-pool">
         <!----><query-distributor xsi:type="query-distributor-ref" ref="first-pair-distributor"/><!---->
            <invoker xsi:type="invoker-class" class="group.id.PageVisitorInvoker"/>
            <endpoint-provider xsi:type="endpoint-provider-list">
                <endpoint>https://jagger.griddynamics.net</endpoint>
            </endpoint-provider>
            <query-provider xsi:type="query-provider-list">
                <query>index.html</query>
                <query>screenshots.html</query>
                <query>download.html</query>
            </query-provider>
        </scenario>
    </test-description>

And that is it.

For more examples take a look at Samples.