use of com.twitter.distributedlog.DistributedLogConfiguration 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.DistributedLogConfiguration 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.DistributedLogConfiguration in project distributedlog by twitter.
the class TestDistributedLogService method testAcquireStreamsWhenExceedMaxAcquiredPartitions.
@Test(timeout = 60000)
public void testAcquireStreamsWhenExceedMaxAcquiredPartitions() throws Exception {
String streamName = testName.getMethodName() + "_0000";
DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
confLocal.addConfiguration(dlConf);
confLocal.setMaxCachedPartitionsPerProxy(-1);
confLocal.setMaxAcquiredPartitionsPerProxy(1);
ServerConfiguration serverConfLocal = new ServerConfiguration();
serverConfLocal.addConfiguration(serverConf);
serverConfLocal.setStreamPartitionConverterClass(DelimiterStreamPartitionConverter.class);
DistributedLogServiceImpl serviceLocal = createService(serverConfLocal, confLocal);
Stream stream = serviceLocal.getLogWriter(streamName);
// stream is cached
assertNotNull(stream);
assertEquals(1, serviceLocal.getStreamManager().numCached());
// create write ops
WriteOp op0 = createWriteOp(service, streamName, 0L);
stream.submit(op0);
WriteResponse wr0 = Await.result(op0.result());
assertEquals("Op 0 should succeed", StatusCode.SUCCESS, wr0.getHeader().getCode());
assertEquals(1, serviceLocal.getStreamManager().numAcquired());
// should be able to cache partitions from same stream
String anotherStreamName = testName.getMethodName() + "_0001";
Stream anotherStream = serviceLocal.getLogWriter(anotherStreamName);
assertNotNull(anotherStream);
assertEquals(2, serviceLocal.getStreamManager().numCached());
// create write ops
WriteOp op1 = createWriteOp(service, anotherStreamName, 0L);
anotherStream.submit(op1);
WriteResponse wr1 = Await.result(op1.result());
assertEquals("Op 1 should fail", StatusCode.STREAM_UNAVAILABLE, wr1.getHeader().getCode());
assertEquals(1, serviceLocal.getStreamManager().numAcquired());
}
use of com.twitter.distributedlog.DistributedLogConfiguration in project distributedlog by twitter.
the class TestDistributedLogService method setup.
@Before
@Override
public void setup() throws Exception {
super.setup();
dlConf = new DistributedLogConfiguration();
dlConf.addConfiguration(conf);
dlConf.setLockTimeout(0).setOutputBufferSize(0).setPeriodicFlushFrequencyMilliSeconds(10);
serverConf = newLocalServerConf();
uri = createDLMURI("/" + testName.getMethodName());
ensureURICreated(uri);
service = createService(serverConf, dlConf, latch);
}
use of com.twitter.distributedlog.DistributedLogConfiguration in project distributedlog by twitter.
the class TestDistributedLogService method newLocalConf.
private DistributedLogConfiguration newLocalConf() {
DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
confLocal.addConfiguration(dlConf);
return confLocal;
}
Aggregations