Search in sources :

Example 41 with DistributedLogConfiguration

use of com.twitter.distributedlog.DistributedLogConfiguration in project distributedlog by twitter.

the class TestZKLogSegmentMetadataStore method setup.

@Before
public void setup() throws Exception {
    zkc = TestZooKeeperClientBuilder.newBuilder().uri(createDLMURI("/")).sessionTimeoutMs(zkSessionTimeoutMs).build();
    scheduler = OrderedScheduler.newBuilder().name("test-zk-logsegment-metadata-store").corePoolSize(1).build();
    DistributedLogConfiguration conf = new DistributedLogConfiguration();
    conf.addConfiguration(baseConf);
    this.uri = createDLMURI("/" + runtime.getMethodName());
    lsmStore = new ZKLogSegmentMetadataStore(conf, zkc, scheduler);
    zkc.get().create("/" + runtime.getMethodName(), new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    this.rootZkPath = "/" + runtime.getMethodName();
}
Also used : DistributedLogConfiguration(com.twitter.distributedlog.DistributedLogConfiguration) Before(org.junit.Before)

Example 42 with DistributedLogConfiguration

use of com.twitter.distributedlog.DistributedLogConfiguration in project distributedlog by twitter.

the class TestZKAccessControlManager method setup.

@Before
public void setup() throws Exception {
    executorService = Executors.newSingleThreadScheduledExecutor();
    zkc = TestZooKeeperClientBuilder.newBuilder().uri(createURI("/")).build();
    conf = new DistributedLogConfiguration();
}
Also used : DistributedLogConfiguration(com.twitter.distributedlog.DistributedLogConfiguration) Before(org.junit.Before)

Example 43 with DistributedLogConfiguration

use of com.twitter.distributedlog.DistributedLogConfiguration in project distributedlog by twitter.

the class TestLedgerAllocatorPool method testNonAvailableAllocator.

@Test(timeout = 60000)
public void testNonAvailableAllocator() throws Exception {
    String allocationPath = "/nonAvailableAllocator";
    DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
    confLocal.addConfiguration(dlConf);
    confLocal.setEnsembleSize(2 * numBookies);
    confLocal.setWriteQuorumSize(2 * numBookies);
    int numAllocators = 3;
    LedgerAllocatorPool pool = new LedgerAllocatorPool(allocationPath, numAllocators, confLocal, zkc, bkc, allocationExecutor);
    for (int i = 0; i < numAllocators; i++) {
        try {
            pool.allocate();
            FutureUtils.result(pool.tryObtain(newTxn(), NULL_LISTENER));
            fail("Should fail to allocate ledger if there are enought bookies");
        } catch (SimpleLedgerAllocator.AllocationException ae) {
            assertEquals(SimpleLedgerAllocator.Phase.ERROR, ae.getPhase());
        }
    }
    for (int i = 0; i < numAllocators; i++) {
        try {
            pool.allocate();
            FutureUtils.result(pool.tryObtain(newTxn(), NULL_LISTENER));
            fail("Should fail to allocate ledger if there aren't available allocators");
        } catch (SimpleLedgerAllocator.AllocationException ae) {
            assertEquals(SimpleLedgerAllocator.Phase.ERROR, ae.getPhase());
        } catch (IOException ioe) {
        // expected
        }
    }
    Utils.close(pool);
}
Also used : DistributedLogConfiguration(com.twitter.distributedlog.DistributedLogConfiguration) IOException(java.io.IOException) Test(org.junit.Test)

Example 44 with DistributedLogConfiguration

use of com.twitter.distributedlog.DistributedLogConfiguration in project distributedlog by twitter.

the class TestConfigurationSubscription method testAddReloadBasicsConfig.

@Test(timeout = 60000)
public void testAddReloadBasicsConfig() throws Exception {
    PropertiesWriter writer = new PropertiesWriter();
    DeterministicScheduler mockScheduler = new DeterministicScheduler();
    FileConfigurationBuilder builder = new PropertiesConfigurationBuilder(writer.getFile().toURI().toURL());
    ConcurrentConstConfiguration conf = new ConcurrentConstConfiguration(new DistributedLogConfiguration());
    List<FileConfigurationBuilder> fileConfigBuilders = Lists.newArrayList(builder);
    ConfigurationSubscription confSub = new ConfigurationSubscription(conf, fileConfigBuilders, mockScheduler, 100, TimeUnit.MILLISECONDS);
    assertEquals(null, conf.getProperty("prop1"));
    // add
    writer.setProperty("prop1", "1");
    writer.save();
    // ensure the file change reloading event can be triggered
    ensureConfigReloaded();
    mockScheduler.tick(100, TimeUnit.MILLISECONDS);
    assertEquals("1", conf.getProperty("prop1"));
}
Also used : DistributedLogConfiguration(com.twitter.distributedlog.DistributedLogConfiguration) DeterministicScheduler(org.jmock.lib.concurrent.DeterministicScheduler) Test(org.junit.Test)

Example 45 with DistributedLogConfiguration

use of com.twitter.distributedlog.DistributedLogConfiguration in project distributedlog by twitter.

the class TestConfigurationSubscription method testExceptionInConfigLoad.

@Test(timeout = 60000)
public void testExceptionInConfigLoad() throws Exception {
    PropertiesWriter writer = new PropertiesWriter();
    writer.setProperty("prop1", "1");
    writer.save();
    DeterministicScheduler mockScheduler = new DeterministicScheduler();
    FileConfigurationBuilder builder = new PropertiesConfigurationBuilder(writer.getFile().toURI().toURL());
    ConcurrentConstConfiguration conf = new ConcurrentConstConfiguration(new DistributedLogConfiguration());
    List<FileConfigurationBuilder> fileConfigBuilders = Lists.newArrayList(builder);
    ConfigurationSubscription confSub = new ConfigurationSubscription(conf, fileConfigBuilders, mockScheduler, 100, TimeUnit.MILLISECONDS);
    final AtomicInteger count = new AtomicInteger(1);
    conf.addConfigurationListener(new ConfigurationListener() {

        @Override
        public void configurationChanged(ConfigurationEvent event) {
            LOG.info("config changed {}", event);
            // Throw after so we actually see the update anyway.
            if (!event.isBeforeUpdate()) {
                count.getAndIncrement();
                throw new RuntimeException("config listener threw and exception");
            }
        }
    });
    int i = 0;
    int initial = 0;
    while (count.get() == initial) {
        writer.setProperty("prop1", Integer.toString(i++));
        writer.save();
        mockScheduler.tick(100, TimeUnit.MILLISECONDS);
    }
    initial = count.get();
    while (count.get() == initial) {
        writer.setProperty("prop1", Integer.toString(i++));
        writer.save();
        mockScheduler.tick(100, TimeUnit.MILLISECONDS);
    }
}
Also used : ConfigurationEvent(org.apache.commons.configuration.event.ConfigurationEvent) ConfigurationListener(org.apache.commons.configuration.event.ConfigurationListener) DistributedLogConfiguration(com.twitter.distributedlog.DistributedLogConfiguration) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DeterministicScheduler(org.jmock.lib.concurrent.DeterministicScheduler) Test(org.junit.Test)

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