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");
}
}
}
}
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));
}
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);
}
}
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"));
}
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());
}
Aggregations