Search in sources :

Example 36 with DistributedLogConfiguration

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());
}
Also used : Partition(com.twitter.distributedlog.service.streamset.Partition) DistributedLogConfiguration(com.twitter.distributedlog.DistributedLogConfiguration) DynamicDistributedLogConfiguration(com.twitter.distributedlog.config.DynamicDistributedLogConfiguration) DistributedLogNamespace(com.twitter.distributedlog.namespace.DistributedLogNamespace) StreamConfigProvider(com.twitter.distributedlog.service.config.StreamConfigProvider) StreamPartitionConverter(com.twitter.distributedlog.service.streamset.StreamPartitionConverter) Test(org.junit.Test)

Example 37 with DistributedLogConfiguration

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());
}
Also used : DistributedLogConfiguration(com.twitter.distributedlog.DistributedLogConfiguration) DynamicDistributedLogConfiguration(com.twitter.distributedlog.config.DynamicDistributedLogConfiguration) ConcurrentConstConfiguration(com.twitter.distributedlog.config.ConcurrentConstConfiguration) DynamicDistributedLogConfiguration(com.twitter.distributedlog.config.DynamicDistributedLogConfiguration) SettableFeature(org.apache.bookkeeper.feature.SettableFeature) Test(org.junit.Test)

Example 38 with DistributedLogConfiguration

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());
}
Also used : DistributedLogConfiguration(com.twitter.distributedlog.DistributedLogConfiguration) WriteOp(com.twitter.distributedlog.service.stream.WriteOp) ServerConfiguration(com.twitter.distributedlog.service.config.ServerConfiguration) WriteResponse(com.twitter.distributedlog.thrift.service.WriteResponse) Stream(com.twitter.distributedlog.service.stream.Stream) Test(org.junit.Test)

Example 39 with DistributedLogConfiguration

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);
}
Also used : DistributedLogConfiguration(com.twitter.distributedlog.DistributedLogConfiguration) Before(org.junit.Before)

Example 40 with DistributedLogConfiguration

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;
}
Also used : DistributedLogConfiguration(com.twitter.distributedlog.DistributedLogConfiguration)

Aggregations

DistributedLogConfiguration (com.twitter.distributedlog.DistributedLogConfiguration)50 Test (org.junit.Test)32 URI (java.net.URI)12 IOException (java.io.IOException)7 DynamicDistributedLogConfiguration (com.twitter.distributedlog.config.DynamicDistributedLogConfiguration)6 WriteResponse (com.twitter.distributedlog.thrift.service.WriteResponse)6 Before (org.junit.Before)6 ZooKeeperClient (com.twitter.distributedlog.ZooKeeperClient)5 ServerConfiguration (com.twitter.distributedlog.service.config.ServerConfiguration)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 StreamManagerImpl (com.twitter.distributedlog.service.stream.StreamManagerImpl)4 Future (com.twitter.util.Future)4 ArrayList (java.util.ArrayList)4 ConfigurationException (org.apache.commons.configuration.ConfigurationException)4 DistributedLogManager (com.twitter.distributedlog.DistributedLogManager)3 ConcurrentConstConfiguration (com.twitter.distributedlog.config.ConcurrentConstConfiguration)3 PropertiesWriter (com.twitter.distributedlog.config.PropertiesWriter)3 DistributedLogNamespace (com.twitter.distributedlog.namespace.DistributedLogNamespace)3 StreamConfigProvider (com.twitter.distributedlog.service.config.StreamConfigProvider)3 Stream (com.twitter.distributedlog.service.stream.Stream)3