Search in sources :

Example 6 with DynamicDistributedLogConfiguration

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

Example 7 with DynamicDistributedLogConfiguration

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

Example 8 with DynamicDistributedLogConfiguration

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());
}
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 9 with DynamicDistributedLogConfiguration

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());
}
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 10 with DynamicDistributedLogConfiguration

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());
}
Also used : IdentityStreamPartitionConverter(com.twitter.distributedlog.service.streamset.IdentityStreamPartitionConverter) DynamicDistributedLogConfiguration(com.twitter.distributedlog.config.DynamicDistributedLogConfiguration) Test(org.junit.Test)

Aggregations

DynamicDistributedLogConfiguration (com.twitter.distributedlog.config.DynamicDistributedLogConfiguration)13 Test (org.junit.Test)9 DistributedLogConfiguration (com.twitter.distributedlog.DistributedLogConfiguration)6 ConcurrentConstConfiguration (com.twitter.distributedlog.config.ConcurrentConstConfiguration)4 DistributedLogNamespace (com.twitter.distributedlog.namespace.DistributedLogNamespace)3 StreamConfigProvider (com.twitter.distributedlog.service.config.StreamConfigProvider)3 IdentityStreamPartitionConverter (com.twitter.distributedlog.service.streamset.IdentityStreamPartitionConverter)3 StreamPartitionConverter (com.twitter.distributedlog.service.streamset.StreamPartitionConverter)3 SettableFeature (org.apache.bookkeeper.feature.SettableFeature)3 PropertiesWriter (com.twitter.distributedlog.config.PropertiesWriter)2 Partition (com.twitter.distributedlog.service.streamset.Partition)2 URI (java.net.URI)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 LedgerAllocator (com.twitter.distributedlog.bk.LedgerAllocator)1 ConcurrentBaseConfiguration (com.twitter.distributedlog.config.ConcurrentBaseConfiguration)1 DynamicConfigurationFactory (com.twitter.distributedlog.config.DynamicConfigurationFactory)1 StreamUnavailableException (com.twitter.distributedlog.exceptions.StreamUnavailableException)1 NOPAnnouncer (com.twitter.distributedlog.service.announcer.NOPAnnouncer)1 ServerSetAnnouncer (com.twitter.distributedlog.service.announcer.ServerSetAnnouncer)1