use of com.twitter.distributedlog.config.DynamicDistributedLogConfiguration in project distributedlog by twitter.
the class TestServiceRequestLimiter method testDynamicLimiter.
@Test(timeout = 60000)
public void testDynamicLimiter() throws Exception {
final AtomicInteger id = new AtomicInteger(0);
final DynamicDistributedLogConfiguration dynConf = new DynamicDistributedLogConfiguration(new ConcurrentConstConfiguration(new DistributedLogConfiguration()));
DynamicRequestLimiter<MockRequest> limiter = new DynamicRequestLimiter<MockRequest>(dynConf, NullStatsLogger.INSTANCE, new SettableFeature("", 0)) {
@Override
public RequestLimiter<MockRequest> build() {
id.getAndIncrement();
return new MockRequestLimiter();
}
};
limiter.initialize();
assertEquals(1, id.get());
dynConf.setProperty("test1", 1);
assertEquals(2, id.get());
dynConf.setProperty("test2", 2);
assertEquals(3, id.get());
}
use of com.twitter.distributedlog.config.DynamicDistributedLogConfiguration in project distributedlog by twitter.
the class TestServiceRequestLimiter method testDynamicLimiterWithException.
@Test(timeout = 60000)
public void testDynamicLimiterWithException() throws Exception {
final AtomicInteger id = new AtomicInteger(0);
final DynamicDistributedLogConfiguration dynConf = new DynamicDistributedLogConfiguration(new ConcurrentConstConfiguration(new DistributedLogConfiguration()));
DynamicRequestLimiter<MockRequest> limiter = new DynamicRequestLimiter<MockRequest>(dynConf, NullStatsLogger.INSTANCE, new SettableFeature("", 0)) {
@Override
public RequestLimiter<MockRequest> build() {
if (id.incrementAndGet() >= 2) {
throw new RuntimeException("exception in dynamic limiter build()");
}
return new MockRequestLimiter();
}
};
limiter.initialize();
assertEquals(1, id.get());
try {
dynConf.setProperty("test1", 1);
fail("should have thrown on config failure");
} catch (RuntimeException ex) {
}
assertEquals(2, id.get());
}
use of com.twitter.distributedlog.config.DynamicDistributedLogConfiguration in project distributedlog by twitter.
the class TestStreamManager method testCollectionMethods.
@Test(timeout = 60000)
public void testCollectionMethods() throws Exception {
Stream mockStream = mock(Stream.class);
when(mockStream.getStreamName()).thenReturn("stream1");
when(mockStream.getPartition()).thenReturn(new Partition("stream1", 0));
StreamFactory mockStreamFactory = mock(StreamFactory.class);
StreamPartitionConverter mockPartitionConverter = mock(StreamPartitionConverter.class);
StreamConfigProvider mockStreamConfigProvider = mock(StreamConfigProvider.class);
when(mockStreamFactory.create((String) any(), (DynamicDistributedLogConfiguration) any(), (StreamManager) any())).thenReturn(mockStream);
StreamManager streamManager = new StreamManagerImpl("", new DistributedLogConfiguration(), mockExecutorService, mockStreamFactory, mockPartitionConverter, mockStreamConfigProvider, mock(DistributedLogNamespace.class));
assertFalse(streamManager.isAcquired("stream1"));
assertEquals(0, streamManager.numAcquired());
assertEquals(0, streamManager.numCached());
streamManager.notifyAcquired(mockStream);
assertTrue(streamManager.isAcquired("stream1"));
assertEquals(1, streamManager.numAcquired());
assertEquals(0, streamManager.numCached());
streamManager.notifyReleased(mockStream);
assertFalse(streamManager.isAcquired("stream1"));
assertEquals(0, streamManager.numAcquired());
assertEquals(0, streamManager.numCached());
streamManager.notifyAcquired(mockStream);
assertTrue(streamManager.isAcquired("stream1"));
assertEquals(1, streamManager.numAcquired());
assertEquals(0, streamManager.numCached());
streamManager.notifyAcquired(mockStream);
assertTrue(streamManager.isAcquired("stream1"));
assertEquals(1, streamManager.numAcquired());
assertEquals(0, streamManager.numCached());
streamManager.notifyReleased(mockStream);
assertFalse(streamManager.isAcquired("stream1"));
assertEquals(0, streamManager.numAcquired());
assertEquals(0, streamManager.numCached());
streamManager.notifyReleased(mockStream);
assertFalse(streamManager.isAcquired("stream1"));
assertEquals(0, streamManager.numAcquired());
assertEquals(0, streamManager.numCached());
}
use of com.twitter.distributedlog.config.DynamicDistributedLogConfiguration in project distributedlog by twitter.
the class TestServiceRequestLimiter method testDynamicLimiterWithDisabledFeature.
@Test(timeout = 60000)
public void testDynamicLimiterWithDisabledFeature() throws Exception {
final DynamicDistributedLogConfiguration dynConf = new DynamicDistributedLogConfiguration(new ConcurrentConstConfiguration(new DistributedLogConfiguration()));
final MockSoftRequestLimiter rateLimiter = new MockSoftRequestLimiter(0);
final SettableFeature disabledFeature = new SettableFeature("", 0);
DynamicRequestLimiter<MockRequest> limiter = new DynamicRequestLimiter<MockRequest>(dynConf, NullStatsLogger.INSTANCE, disabledFeature) {
@Override
public RequestLimiter<MockRequest> build() {
return rateLimiter;
}
};
limiter.initialize();
assertEquals(0, rateLimiter.getLimitHitCount());
// Not disabled, rate limiter was invoked
limiter.apply(new MockRequest(Integer.MAX_VALUE));
assertEquals(1, rateLimiter.getLimitHitCount());
// Disabled, rate limiter not invoked
disabledFeature.set(1);
limiter.apply(new MockRequest(Integer.MAX_VALUE));
assertEquals(1, rateLimiter.getLimitHitCount());
}
use of com.twitter.distributedlog.config.DynamicDistributedLogConfiguration in project distributedlog by twitter.
the class TestStreamConfigProvider method testServiceProviderWithMissingConfig.
@Test(timeout = 60000)
public void testServiceProviderWithMissingConfig() throws Exception {
StreamConfigProvider provider = getServiceProvider(new IdentityStreamPartitionConverter());
Optional<DynamicDistributedLogConfiguration> config = provider.getDynamicStreamConfig("stream1");
assertTrue(config.isPresent());
}
Aggregations