Search in sources :

Example 21 with BaseConfiguration

use of org.apache.commons.configuration.BaseConfiguration in project pinot by linkedin.

the class KafkaLowLevelConsumerRoutingTableBuilderTest method testMultipleConsumingSegments.

@Test
public void testMultipleConsumingSegments() {
    final int SEGMENT_COUNT = 10;
    final int ONLINE_SEGMENT_COUNT = 8;
    final int CONSUMING_SEGMENT_COUNT = SEGMENT_COUNT - ONLINE_SEGMENT_COUNT;
    KafkaLowLevelConsumerRoutingTableBuilder routingTableBuilder = new KafkaLowLevelConsumerRoutingTableBuilder();
    routingTableBuilder.init(new BaseConfiguration());
    List<SegmentName> segmentNames = new ArrayList<SegmentName>();
    for (int i = 0; i < SEGMENT_COUNT; ++i) {
        segmentNames.add(new LLCSegmentName("table", 0, i, System.currentTimeMillis()));
    }
    List<InstanceConfig> instanceConfigs = new ArrayList<InstanceConfig>();
    InstanceConfig instanceConfig = new InstanceConfig("Server_localhost_1234");
    instanceConfigs.add(instanceConfig);
    instanceConfig.getRecord().setSimpleField(CommonConstants.Helix.IS_SHUTDOWN_IN_PROGRESS, "false");
    // Generate an external view for a single server with some consuming segments
    ExternalView externalView = new ExternalView("table_REALTIME");
    for (int i = 0; i < ONLINE_SEGMENT_COUNT; i++) {
        externalView.setState(segmentNames.get(i).getSegmentName(), "Server_localhost_1234", "ONLINE");
    }
    for (int i = ONLINE_SEGMENT_COUNT; i < SEGMENT_COUNT; ++i) {
        externalView.setState(segmentNames.get(i).getSegmentName(), "Server_localhost_1234", "CONSUMING");
    }
    List<ServerToSegmentSetMap> routingTables = routingTableBuilder.computeRoutingTableFromExternalView("table", externalView, instanceConfigs);
    for (ServerToSegmentSetMap routingTable : routingTables) {
        for (String server : routingTable.getServerSet()) {
            Set<String> segmentSet = routingTable.getSegmentSet(server);
            assertEquals(segmentSet.size(), ONLINE_SEGMENT_COUNT + 1, "");
            // Should only contain the first consuming segment, not the second
            assertTrue(segmentSet.contains(segmentNames.get(ONLINE_SEGMENT_COUNT).getSegmentName()), "Segment set does not contain the first segment in consuming state");
            for (int i = ONLINE_SEGMENT_COUNT + 1; i < SEGMENT_COUNT; i++) {
                assertFalse(segmentSet.contains(segmentNames.get(i).getSegmentName()), "Segment set contains a segment in consuming state that should not be there");
            }
        }
    }
}
Also used : ExternalView(org.apache.helix.model.ExternalView) SegmentName(com.linkedin.pinot.common.utils.SegmentName) LLCSegmentName(com.linkedin.pinot.common.utils.LLCSegmentName) ArrayList(java.util.ArrayList) ServerToSegmentSetMap(com.linkedin.pinot.routing.ServerToSegmentSetMap) LLCSegmentName(com.linkedin.pinot.common.utils.LLCSegmentName) BaseConfiguration(org.apache.commons.configuration.BaseConfiguration) InstanceConfig(org.apache.helix.model.InstanceConfig) Test(org.testng.annotations.Test)

Example 22 with BaseConfiguration

use of org.apache.commons.configuration.BaseConfiguration in project pinot by linkedin.

the class RandomRoutingTableTest method testHelixExternalViewBasedRoutingTable.

@Test
public void testHelixExternalViewBasedRoutingTable() throws Exception {
    URL resourceUrl = getClass().getClassLoader().getResource("SampleExternalView.json");
    Assert.assertNotNull(resourceUrl);
    String fileName = resourceUrl.getFile();
    String tableName = "testTable_OFFLINE";
    InputStream evInputStream = new FileInputStream(fileName);
    ZNRecordSerializer znRecordSerializer = new ZNRecordSerializer();
    ZNRecord externalViewRecord = (ZNRecord) znRecordSerializer.deserialize(IOUtils.toByteArray(evInputStream));
    int totalRuns = 10000;
    RoutingTableBuilder routingStrategy = new BalancedRandomRoutingTableBuilder(10);
    HelixExternalViewBasedRouting routingTable = new HelixExternalViewBasedRouting(null, new PercentageBasedRoutingTableSelector(), null, new BaseConfiguration());
    routingTable.setSmallClusterRoutingTableBuilder(routingStrategy);
    ExternalView externalView = new ExternalView(externalViewRecord);
    routingTable.markDataResourceOnline(tableName, externalView, getInstanceConfigs(externalView));
    double[] globalArrays = new double[9];
    for (int numRun = 0; numRun < totalRuns; ++numRun) {
        RoutingTableLookupRequest request = new RoutingTableLookupRequest(tableName, Collections.<String>emptyList());
        Map<ServerInstance, SegmentIdSet> serversMap = routingTable.findServers(request);
        TreeSet<ServerInstance> serverInstances = new TreeSet<ServerInstance>(serversMap.keySet());
        int i = 0;
        double[] arrays = new double[9];
        for (ServerInstance serverInstance : serverInstances) {
            globalArrays[i] += serversMap.get(serverInstance).getSegments().size();
            arrays[i++] = serversMap.get(serverInstance).getSegments().size();
        }
        for (int j = 0; i < arrays.length; ++j) {
            Assert.assertTrue(arrays[j] / totalRuns <= 31);
            Assert.assertTrue(arrays[j] / totalRuns >= 28);
        }
    //      System.out.println(Arrays.toString(arrays) + " : " + new StandardDeviation().evaluate(arrays) + " : " + new Mean().evaluate(arrays));
    }
    for (int i = 0; i < globalArrays.length; ++i) {
        Assert.assertTrue(globalArrays[i] / totalRuns <= 31);
        Assert.assertTrue(globalArrays[i] / totalRuns >= 28);
    }
//    System.out.println(Arrays.toString(globalArrays) + " : " + new StandardDeviation().evaluate(globalArrays) + " : "
//        + new Mean().evaluate(globalArrays));
}
Also used : BalancedRandomRoutingTableBuilder(com.linkedin.pinot.routing.builder.BalancedRandomRoutingTableBuilder) RoutingTableBuilder(com.linkedin.pinot.routing.builder.RoutingTableBuilder) ExternalView(org.apache.helix.model.ExternalView) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) URL(java.net.URL) FileInputStream(java.io.FileInputStream) BaseConfiguration(org.apache.commons.configuration.BaseConfiguration) BalancedRandomRoutingTableBuilder(com.linkedin.pinot.routing.builder.BalancedRandomRoutingTableBuilder) TreeSet(java.util.TreeSet) SegmentIdSet(com.linkedin.pinot.transport.common.SegmentIdSet) ServerInstance(com.linkedin.pinot.common.response.ServerInstance) ZNRecord(org.apache.helix.ZNRecord) ZNRecordSerializer(org.apache.helix.manager.zk.ZNRecordSerializer) Test(org.testng.annotations.Test)

Example 23 with BaseConfiguration

use of org.apache.commons.configuration.BaseConfiguration in project archaius by Netflix.

the class TestConfigurationFactory method testConfigurationFactory.

@Test
public void testConfigurationFactory() {
    Object configSource = DynamicPropertyFactory.getInstance().getBackingConfigurationSource();
    AbstractConfiguration config = ConfigurationManager.getConfigInstance();
    assertTrue(ConfigurationManager.isConfigurationInstalled());
    assertTrue(configSource == config);
    assertTrue(config == TestConfigurationFactory.getInstance());
    try {
        DynamicPropertyFactory.initWithConfigurationSource(new BaseConfiguration());
        fail("IllegalStateException expected");
    } catch (IllegalStateException e) {
        assertNotNull(e);
    }
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) BaseConfiguration(org.apache.commons.configuration.BaseConfiguration) Test(org.junit.Test)

Example 24 with BaseConfiguration

use of org.apache.commons.configuration.BaseConfiguration in project archaius by Netflix.

the class PollingSourceTest method testDeletingPollingSource.

@Test
public void testDeletingPollingSource() throws Exception {
    BaseConfiguration config = new BaseConfiguration();
    config.addProperty("prop1", "original");
    DummyPollingSource source = new DummyPollingSource(false);
    source.setFull("prop1=changed");
    FixedDelayPollingScheduler scheduler = new FixedDelayPollingScheduler(0, 10, false);
    ConfigurationWithPollingSource pollingConfig = new ConfigurationWithPollingSource(config, source, scheduler);
    Thread.sleep(200);
    assertEquals("changed", pollingConfig.getProperty("prop1"));
    source.setFull("");
    Thread.sleep(250);
    assertFalse(pollingConfig.containsKey("prop1"));
    source.setFull("prop1=changedagain,prop2=new");
    Thread.sleep(200);
    assertEquals("changedagain", pollingConfig.getProperty("prop1"));
    assertEquals("new", pollingConfig.getProperty("prop2"));
    source.setFull("prop3=new");
    Thread.sleep(200);
    assertFalse(pollingConfig.containsKey("prop1"));
    assertFalse(pollingConfig.containsKey("prop2"));
    assertEquals("new", pollingConfig.getProperty("prop3"));
}
Also used : BaseConfiguration(org.apache.commons.configuration.BaseConfiguration) Test(org.junit.Test)

Example 25 with BaseConfiguration

use of org.apache.commons.configuration.BaseConfiguration in project archaius by Netflix.

the class PollingSourceTest method testIncrementalPollingSource.

@Test
public void testIncrementalPollingSource() throws Exception {
    BaseConfiguration config = new BaseConfiguration();
    DynamicPropertyFactory.initWithConfigurationSource(config);
    DynamicStringProperty prop1 = new DynamicStringProperty("prop1", null);
    DynamicStringProperty prop2 = new DynamicStringProperty("prop2", null);
    config.addProperty("prop1", "original");
    DummyPollingSource source = new DummyPollingSource(true);
    FixedDelayPollingScheduler scheduler = new FixedDelayPollingScheduler(0, 10, true);
    scheduler.setIgnoreDeletesFromSource(false);
    // ConfigurationWithPollingSource pollingConfig = new ConfigurationWithPollingSource(config, source,scheduler);
    scheduler.startPolling(source, config);
    assertEquals("original", config.getProperty("prop1"));
    assertEquals("original", prop1.get());
    source.setAdded("prop2=new");
    Thread.sleep(200);
    assertEquals("original", config.getProperty("prop1"));
    assertEquals("new", config.getProperty("prop2"));
    assertEquals("new", prop2.get());
    source.setDeleted("prop1=DoesNotMatter");
    source.setChanged("prop2=changed");
    source.setAdded("");
    Thread.sleep(200);
    assertFalse(config.containsKey("prop1"));
    assertNull(prop1.get());
    assertEquals("changed", config.getProperty("prop2"));
    assertEquals("changed", prop2.get());
}
Also used : BaseConfiguration(org.apache.commons.configuration.BaseConfiguration) Test(org.junit.Test)

Aggregations

BaseConfiguration (org.apache.commons.configuration.BaseConfiguration)32 Test (org.junit.Test)17 CommonsConfiguration (com.thinkaurelius.titan.diskstorage.configuration.backend.CommonsConfiguration)8 ExternalView (org.apache.helix.model.ExternalView)7 Test (org.testng.annotations.Test)7 ModifiableConfiguration (com.thinkaurelius.titan.diskstorage.configuration.ModifiableConfiguration)5 GraphDatabaseConfiguration (com.thinkaurelius.titan.graphdb.configuration.GraphDatabaseConfiguration)5 InstanceConfig (org.apache.helix.model.InstanceConfig)5 LLCSegmentName (com.linkedin.pinot.common.utils.LLCSegmentName)4 BasicConfiguration (com.thinkaurelius.titan.diskstorage.configuration.BasicConfiguration)4 Configuration (com.thinkaurelius.titan.diskstorage.configuration.Configuration)4 ElasticSearchIndex (com.thinkaurelius.titan.diskstorage.es.ElasticSearchIndex)4 ArrayList (java.util.ArrayList)4 AbstractConfiguration (org.apache.commons.configuration.AbstractConfiguration)4 RoutingTableBuilder (com.linkedin.pinot.routing.builder.RoutingTableBuilder)3 File (java.io.File)3 Configuration (org.apache.commons.configuration.Configuration)3 ServerInstance (com.linkedin.pinot.common.response.ServerInstance)2 HLCSegmentName (com.linkedin.pinot.common.utils.HLCSegmentName)2 ServerToSegmentSetMap (com.linkedin.pinot.routing.ServerToSegmentSetMap)2