Search in sources :

Example 1 with DarkClusterStrategyFactoryImpl

use of com.linkedin.darkcluster.impl.DarkClusterStrategyFactoryImpl in project rest.li by linkedin.

the class TestDarkClusterStrategyFactory method setup.

@BeforeMethod
public void setup() {
    _clusterInfoProvider = new MockClusterInfoProvider();
    Facilities facilities = new MockFacilities(_clusterInfoProvider);
    DarkClusterConfig darkClusterConfigOld = createRelativeTrafficMultiplierConfig(0.5f);
    _clusterInfoProvider.addDarkClusterConfig(SOURCE_CLUSTER_NAME, PREEXISTING_DARK_CLUSTER_NAME, darkClusterConfigOld);
    DarkClusterDispatcher darkClusterDispatcher = new DefaultDarkClusterDispatcher(new MockClient(false));
    ClockedExecutor executor = new ClockedExecutor();
    _rateLimiterSupplier = () -> new ConstantQpsRateLimiter(executor, executor, executor, TestConstantQpsDarkClusterStrategy.getBuffer(executor));
    _strategyFactory = new DarkClusterStrategyFactoryImpl(facilities, SOURCE_CLUSTER_NAME, darkClusterDispatcher, new DoNothingNotifier(), new Random(SEED), new CountingVerifierManager(), _rateLimiterSupplier);
    _strategyFactory.start();
}
Also used : DefaultDarkClusterDispatcher(com.linkedin.darkcluster.impl.DefaultDarkClusterDispatcher) DarkClusterDispatcher(com.linkedin.darkcluster.api.DarkClusterDispatcher) DefaultDarkClusterDispatcher(com.linkedin.darkcluster.impl.DefaultDarkClusterDispatcher) ClockedExecutor(com.linkedin.test.util.ClockedExecutor) DarkClusterStrategyFactoryImpl(com.linkedin.darkcluster.impl.DarkClusterStrategyFactoryImpl) Facilities(com.linkedin.d2.balancer.Facilities) ConstantQpsRateLimiter(com.linkedin.r2.transport.http.client.ConstantQpsRateLimiter) Random(java.util.Random) DarkClusterConfig(com.linkedin.d2.DarkClusterConfig) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 2 with DarkClusterStrategyFactoryImpl

use of com.linkedin.darkcluster.impl.DarkClusterStrategyFactoryImpl 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 3 with DarkClusterStrategyFactoryImpl

use of com.linkedin.darkcluster.impl.DarkClusterStrategyFactoryImpl 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

DarkClusterStrategyFactoryImpl (com.linkedin.darkcluster.impl.DarkClusterStrategyFactoryImpl)3 DarkClusterConfig (com.linkedin.d2.DarkClusterConfig)2 DarkClusterManager (com.linkedin.darkcluster.api.DarkClusterManager)2 DarkClusterFilter (com.linkedin.darkcluster.filter.DarkClusterFilter)2 DarkClusterManagerImpl (com.linkedin.darkcluster.impl.DarkClusterManagerImpl)2 DefaultDarkClusterDispatcher (com.linkedin.darkcluster.impl.DefaultDarkClusterDispatcher)2 BeforeMethod (org.testng.annotations.BeforeMethod)2 Facilities (com.linkedin.d2.balancer.Facilities)1 LoadBalancerTestState (com.linkedin.d2.balancer.LoadBalancerTestState)1 SimpleLoadBalancer (com.linkedin.d2.balancer.simple.SimpleLoadBalancer)1 DarkClusterDispatcher (com.linkedin.darkcluster.api.DarkClusterDispatcher)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 ConstantQpsRateLimiter (com.linkedin.r2.transport.http.client.ConstantQpsRateLimiter)1 ClockedExecutor (com.linkedin.test.util.ClockedExecutor)1 Random (java.util.Random)1 Test (org.testng.annotations.Test)1