use of org.jmock.lib.concurrent.DeterministicScheduler in project atlasdb by palantir.
the class CassandraMetricMeasurementsLoaderTest method setup.
@Before
public void setup() {
healthMetricSupplier = mock(Supplier.class);
cassandraMetricClient = mock(MetricsService.class);
scheduledExecutorService = new DeterministicScheduler();
cassandraMetricMeasurementsLoader = new CassandraMetricMeasurementsLoader(healthMetricSupplier, cassandraMetricClient, scheduledExecutorService);
when(healthMetricSupplier.get()).thenReturn(ImmutableList.of(getCassandraMetric(METRIC_TYPE_1, METRIC_NAME_1, METRIC_ATTRIBUTE_1), getCassandraMetric(METRIC_TYPE_2, METRIC_NAME_2, METRIC_ATTRIBUTE_2)));
when(cassandraMetricClient.getMetric(METRIC_TYPE_1, METRIC_NAME_1, METRIC_ATTRIBUTE_1, ImmutableMap.of())).thenReturn(METRIC_VALUE_1);
when(cassandraMetricClient.getMetric(METRIC_TYPE_2, METRIC_NAME_2, METRIC_ATTRIBUTE_2, ImmutableMap.of())).thenReturn(METRIC_VALUE_2);
}
use of org.jmock.lib.concurrent.DeterministicScheduler 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"));
}
use of org.jmock.lib.concurrent.DeterministicScheduler 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);
}
}
use of org.jmock.lib.concurrent.DeterministicScheduler in project distributedlog by twitter.
the class TestConfigurationSubscription method testReloadConfiguration.
@Test(timeout = 60000)
public void testReloadConfiguration() throws Exception {
PropertiesWriter writer = new PropertiesWriter();
FileConfigurationBuilder builder = new PropertiesConfigurationBuilder(writer.getFile().toURI().toURL());
ConcurrentConstConfiguration conf = new ConcurrentConstConfiguration(new DistributedLogConfiguration());
DeterministicScheduler executorService = new DeterministicScheduler();
List<FileConfigurationBuilder> fileConfigBuilders = Lists.newArrayList(builder);
ConfigurationSubscription confSub = new ConfigurationSubscription(conf, fileConfigBuilders, executorService, 100, TimeUnit.MILLISECONDS);
final AtomicReference<ConcurrentBaseConfiguration> confHolder = new AtomicReference<>();
confSub.registerListener(new com.twitter.distributedlog.config.ConfigurationListener() {
@Override
public void onReload(ConcurrentBaseConfiguration conf) {
confHolder.set(conf);
}
});
assertEquals(null, conf.getProperty("prop1"));
// add
writer.setProperty("prop1", "1");
writer.save();
// ensure the file change reloading event can be triggered
ensureConfigReloaded();
// reload the config
confSub.reload();
assertNotNull(confHolder.get());
assertTrue(conf == confHolder.get());
assertEquals("1", conf.getProperty("prop1"));
}
Aggregations