Search in sources :

Example 6 with ServerConfiguration

use of com.twitter.distributedlog.service.config.ServerConfiguration 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)

Aggregations

ServerConfiguration (com.twitter.distributedlog.service.config.ServerConfiguration)6 DistributedLogConfiguration (com.twitter.distributedlog.DistributedLogConfiguration)5 WriteResponse (com.twitter.distributedlog.thrift.service.WriteResponse)4 Test (org.junit.Test)4 Stream (com.twitter.distributedlog.service.stream.Stream)2 StreamManagerImpl (com.twitter.distributedlog.service.stream.StreamManagerImpl)2 WriteOp (com.twitter.distributedlog.service.stream.WriteOp)2 Future (com.twitter.util.Future)2 ArrayList (java.util.ArrayList)2 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 DynamicDistributedLogConfiguration (com.twitter.distributedlog.config.DynamicDistributedLogConfiguration)1 StreamUnavailableException (com.twitter.distributedlog.exceptions.StreamUnavailableException)1 NOPAnnouncer (com.twitter.distributedlog.service.announcer.NOPAnnouncer)1 ServerSetAnnouncer (com.twitter.distributedlog.service.announcer.ServerSetAnnouncer)1 DefaultStreamConfigProvider (com.twitter.distributedlog.service.config.DefaultStreamConfigProvider)1 NullStreamConfigProvider (com.twitter.distributedlog.service.config.NullStreamConfigProvider)1 ServiceStreamConfigProvider (com.twitter.distributedlog.service.config.ServiceStreamConfigProvider)1 StreamConfigProvider (com.twitter.distributedlog.service.config.StreamConfigProvider)1 StreamImpl (com.twitter.distributedlog.service.stream.StreamImpl)1 IdentityStreamPartitionConverter (com.twitter.distributedlog.service.streamset.IdentityStreamPartitionConverter)1