Search in sources :

Example 1 with DarkClusterFilter

use of com.linkedin.darkcluster.filter.DarkClusterFilter in project rest.li by linkedin.

the class TestDarkClusterFilter method setup.

@BeforeMethod
public void setup() {
    _client = new MockClient(false);
    _darkClusterDispatcher = new DefaultDarkClusterDispatcher(_client);
    _clusterInfoProvider = new SimpleLoadBalancer(new LoadBalancerTestState(), _scheduledExecutorService);
    _facilities = new MockFacilities(_clusterInfoProvider);
    _darkClusterStrategyFactory = new DarkClusterStrategyFactoryImpl(_facilities, SOURCE_CLUSTER_NAME, _darkClusterDispatcher, _notifier, _random, _verifierManager, _rateLimiterSupplier);
    DarkClusterManager darkClusterManager = new DarkClusterManagerImpl(SOURCE_CLUSTER_NAME, _facilities, _darkClusterStrategyFactory, "", "", _notifier);
    _darkClusterFilter = new DarkClusterFilter(darkClusterManager, _verifierManager);
}
Also used : DefaultDarkClusterDispatcher(com.linkedin.darkcluster.impl.DefaultDarkClusterDispatcher) SimpleLoadBalancer(com.linkedin.d2.balancer.simple.SimpleLoadBalancer) DarkClusterFilter(com.linkedin.darkcluster.filter.DarkClusterFilter) DarkClusterManagerImpl(com.linkedin.darkcluster.impl.DarkClusterManagerImpl) LoadBalancerTestState(com.linkedin.d2.balancer.LoadBalancerTestState) DarkClusterManager(com.linkedin.darkcluster.api.DarkClusterManager) DarkClusterStrategyFactoryImpl(com.linkedin.darkcluster.impl.DarkClusterStrategyFactoryImpl) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 2 with DarkClusterFilter

use of com.linkedin.darkcluster.filter.DarkClusterFilter in project rest.li by linkedin.

the class TestDarkClusterFilter method testDarkClusterAssemblyWithDarkCluster.

@Test
public void testDarkClusterAssemblyWithDarkCluster() {
    // we need to have a Mock clusterInfoProvider in order to set up a dark cluster.
    MockClusterInfoProvider clusterInfoProvider = new MockClusterInfoProvider();
    _facilities = new MockFacilities(clusterInfoProvider);
    _darkClusterStrategyFactory = new DarkClusterStrategyFactoryImpl(_facilities, SOURCE_CLUSTER_NAME, _darkClusterDispatcher, _notifier, _random, _verifierManager, _rateLimiterSupplier);
    _darkClusterStrategyFactory.start();
    DarkClusterManager darkClusterManager = new DarkClusterManagerImpl(SOURCE_CLUSTER_NAME, _facilities, _darkClusterStrategyFactory, "", "", _notifier);
    _darkClusterFilter = new DarkClusterFilter(darkClusterManager, _verifierManager);
    // set the multiplier to 1 so that traffic gets sent.
    DarkClusterConfig darkClusterConfig = createRelativeTrafficMultiplierConfig(1.0f);
    clusterInfoProvider.addDarkClusterConfig(SOURCE_CLUSTER_NAME, DARK_CLUSTER_NAME, darkClusterConfig);
    clusterInfoProvider.notifyListenersClusterAdded(SOURCE_CLUSTER_NAME);
    // send the request, expecting it to make it all the way down to the client
    RestRequest restRequest = new RestRequestBuilder(URI.create("foo")).build();
    _darkClusterFilter.onRestRequest(restRequest, new RequestContext(), new HashMap<>(), new DummyNextFilter());
    Assert.assertEquals(_client.requestAuthorityMap.size(), 1, "expected 1 request to be sent");
    _darkClusterFilter.onRestError(new RuntimeException("test"), new RequestContext(), new HashMap<>(), new DummyNextFilter());
    _darkClusterFilter.onRestResponse(new RestResponseBuilder().build(), new RequestContext(), new HashMap<>(), new DummyNextFilter());
}
Also used : DarkClusterFilter(com.linkedin.darkcluster.filter.DarkClusterFilter) RestResponseBuilder(com.linkedin.r2.message.rest.RestResponseBuilder) DarkClusterStrategyFactoryImpl(com.linkedin.darkcluster.impl.DarkClusterStrategyFactoryImpl) RestRequest(com.linkedin.r2.message.rest.RestRequest) DarkClusterConfig(com.linkedin.d2.DarkClusterConfig) DarkClusterManagerImpl(com.linkedin.darkcluster.impl.DarkClusterManagerImpl) RestRequestBuilder(com.linkedin.r2.message.rest.RestRequestBuilder) RequestContext(com.linkedin.r2.message.RequestContext) DarkClusterManager(com.linkedin.darkcluster.api.DarkClusterManager) Test(org.testng.annotations.Test)

Aggregations

DarkClusterManager (com.linkedin.darkcluster.api.DarkClusterManager)2 DarkClusterFilter (com.linkedin.darkcluster.filter.DarkClusterFilter)2 DarkClusterManagerImpl (com.linkedin.darkcluster.impl.DarkClusterManagerImpl)2 DarkClusterStrategyFactoryImpl (com.linkedin.darkcluster.impl.DarkClusterStrategyFactoryImpl)2 DarkClusterConfig (com.linkedin.d2.DarkClusterConfig)1 LoadBalancerTestState (com.linkedin.d2.balancer.LoadBalancerTestState)1 SimpleLoadBalancer (com.linkedin.d2.balancer.simple.SimpleLoadBalancer)1 DefaultDarkClusterDispatcher (com.linkedin.darkcluster.impl.DefaultDarkClusterDispatcher)1 RequestContext (com.linkedin.r2.message.RequestContext)1 RestRequest (com.linkedin.r2.message.rest.RestRequest)1 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)1 RestResponseBuilder (com.linkedin.r2.message.rest.RestResponseBuilder)1 BeforeMethod (org.testng.annotations.BeforeMethod)1 Test (org.testng.annotations.Test)1