use of com.hazelcast.internal.dynamicconfig.DynamicConfigurationAwareConfig in project hazelcast by hazelcast.
the class GracefulShutdownTest method when_shutdownGracefulWhileRestartGraceful_then_restartsFromTerminalSnapshot.
@Test
public void when_shutdownGracefulWhileRestartGraceful_then_restartsFromTerminalSnapshot() throws Exception {
MapConfig mapConfig = new MapConfig(JobRepository.SNAPSHOT_DATA_MAP_PREFIX + "*");
mapConfig.getMapStoreConfig().setClassName(BlockingMapStore.class.getName()).setEnabled(true);
Config config = instances[0].getConfig();
((DynamicConfigurationAwareConfig) config).getStaticConfig().addMapConfig(mapConfig);
BlockingMapStore.shouldBlock = false;
BlockingMapStore.wasBlocked = false;
DAG dag = new DAG();
int numItems = 5000;
Vertex source = dag.newVertex("source", throttle(() -> new EmitIntegersP(numItems), 500));
Vertex sink = dag.newVertex("sink", SinkProcessors.writeListP("sink"));
dag.edge(between(source, sink));
source.localParallelism(1);
Job job = instances[0].getJet().newJob(dag, new JobConfig().setProcessingGuarantee(EXACTLY_ONCE).setSnapshotIntervalMillis(2000));
// wait for the first snapshot
JetServiceBackend jetServiceBackend = getNode(instances[0]).nodeEngine.getService(JetServiceBackend.SERVICE_NAME);
JobRepository jobRepository = jetServiceBackend.getJobCoordinationService().jobRepository();
assertJobStatusEventually(job, RUNNING);
assertTrueEventually(() -> assertTrue(jobRepository.getJobExecutionRecord(job.getId()).dataMapIndex() >= 0));
// When
BlockingMapStore.shouldBlock = true;
job.restart();
assertTrueEventually(() -> assertTrue("blocking did not happen", BlockingMapStore.wasBlocked), 5);
Future shutdownFuture = spawn(() -> instances[1].shutdown());
logger.info("savedCounters=" + EmitIntegersP.savedCounters);
int minCounter = EmitIntegersP.savedCounters.values().stream().mapToInt(Integer::intValue).min().getAsInt();
BlockingMapStore.shouldBlock = false;
shutdownFuture.get();
// Then
job.join();
Map<Integer, Integer> actual = new ArrayList<>(instances[0].<Integer>getList("sink")).stream().collect(Collectors.toMap(Function.identity(), item -> 1, Integer::sum));
Map<Integer, Integer> expected = IntStream.range(0, numItems).boxed().collect(Collectors.toMap(Function.identity(), item -> item < minCounter ? 2 : 1));
assertEquals(expected, actual);
}
use of com.hazelcast.internal.dynamicconfig.DynamicConfigurationAwareConfig in project hazelcast by hazelcast.
the class ManualRestartTest method when_terminalSnapshotFails_then_previousSnapshotUsed.
@Test
public void when_terminalSnapshotFails_then_previousSnapshotUsed() {
MapConfig mapConfig = new MapConfig(JobRepository.SNAPSHOT_DATA_MAP_PREFIX + "*");
mapConfig.getMapStoreConfig().setClassName(FailingMapStore.class.getName()).setEnabled(true);
Config config = instances[0].getConfig();
((DynamicConfigurationAwareConfig) config).getStaticConfig().addMapConfig(mapConfig);
FailingMapStore.fail = false;
FailingMapStore.failed = false;
DAG dag = new DAG();
Vertex source = dag.newVertex("source", throttle(() -> new SequencesInPartitionsGeneratorP(2, 10000, true), 1000));
Vertex sink = dag.newVertex("sink", writeListP("sink"));
dag.edge(between(source, sink));
source.localParallelism(1);
Job job = instances[0].getJet().newJob(dag, new JobConfig().setProcessingGuarantee(EXACTLY_ONCE).setSnapshotIntervalMillis(2000));
// wait for the first snapshot
JetServiceBackend jetServiceBackend = getNode(instances[0]).nodeEngine.getService(JetServiceBackend.SERVICE_NAME);
JobRepository jobRepository = jetServiceBackend.getJobCoordinationService().jobRepository();
assertJobStatusEventually(job, RUNNING);
assertTrueEventually(() -> assertTrue(jobRepository.getJobExecutionRecord(job.getId()).dataMapIndex() >= 0));
// When
sleepMillis(100);
FailingMapStore.fail = true;
job.restart();
assertTrueEventually(() -> assertTrue(FailingMapStore.failed));
FailingMapStore.fail = false;
job.join();
Map<Integer, Integer> actual = new ArrayList<>(instances[0].<Entry<Integer, Integer>>getList("sink")).stream().filter(// we'll only check partition 0
e -> e.getKey() == 0).map(Entry::getValue).collect(Collectors.toMap(e -> e, e -> 1, (o, n) -> o + n, TreeMap::new));
assertEquals("first item != 1, " + actual.toString(), (Integer) 1, actual.get(0));
assertEquals("last item != 1, " + actual.toString(), (Integer) 1, actual.get(9999));
// the result should be some ones, then some twos and then some ones. The twos should be during the time
// since the last successful snapshot until the actual termination, when there was reprocessing.
boolean sawTwo = false;
boolean sawOneAgain = false;
for (Integer v : actual.values()) {
if (v == 1) {
if (sawTwo) {
sawOneAgain = true;
}
} else if (v == 2) {
assertFalse("got a 2 in another group", sawOneAgain);
sawTwo = true;
} else {
fail("v=" + v);
}
}
assertTrue("didn't see any 2s", sawTwo);
}
use of com.hazelcast.internal.dynamicconfig.DynamicConfigurationAwareConfig in project hazelcast by hazelcast.
the class DynamicConfigurationAwareConfigConstructorTest method testConstructor.
@Test
public void testConstructor() {
Config config = new Config().setInstanceName("myInstanceName").addMapConfig(new MapConfig("myMap")).addListConfig(new ListConfig("myList")).addListenerConfig(new ListenerConfig("com.hazelcast.test.MyListenerConfig")).setProperties(buildPropertiesWithDefaults());
HazelcastProperties properties = new HazelcastProperties(config);
DynamicConfigurationAwareConfig dynamicConfig = new DynamicConfigurationAwareConfig(config, properties);
DynamicConfigurationAwareConfigConstructor constructor = new DynamicConfigurationAwareConfigConstructor(DynamicConfigurationAwareConfig.class);
DynamicConfigurationAwareConfig clonedDynamicConfig = (DynamicConfigurationAwareConfig) constructor.createNew(dynamicConfig);
assertEquals(dynamicConfig.getInstanceName(), clonedDynamicConfig.getInstanceName());
assertEquals(dynamicConfig.getMapConfigs().size(), clonedDynamicConfig.getMapConfigs().size());
assertEquals(dynamicConfig.getListConfigs().size(), clonedDynamicConfig.getListConfigs().size());
assertEquals(dynamicConfig.getListenerConfigs().size(), clonedDynamicConfig.getListenerConfigs().size());
assertPropertiesEquals(dynamicConfig.getProperties(), clonedDynamicConfig.getProperties());
}
use of com.hazelcast.internal.dynamicconfig.DynamicConfigurationAwareConfig in project hazelcast by hazelcast.
the class AddCardinalityEstimatorConfigMessageTask method checkStaticConfigDoesNotExist.
@Override
protected boolean checkStaticConfigDoesNotExist(IdentifiedDataSerializable config) {
DynamicConfigurationAwareConfig nodeConfig = (DynamicConfigurationAwareConfig) nodeEngine.getConfig();
CardinalityEstimatorConfig cardinalityEstimatorConfig = (CardinalityEstimatorConfig) config;
return nodeConfig.checkStaticConfigDoesNotExist(nodeConfig.getStaticConfig().getCardinalityEstimatorConfigs(), cardinalityEstimatorConfig.getName(), cardinalityEstimatorConfig);
}
use of com.hazelcast.internal.dynamicconfig.DynamicConfigurationAwareConfig in project hazelcast by hazelcast.
the class AddExecutorConfigMessageTask method checkStaticConfigDoesNotExist.
@Override
protected boolean checkStaticConfigDoesNotExist(IdentifiedDataSerializable config) {
DynamicConfigurationAwareConfig nodeConfig = (DynamicConfigurationAwareConfig) nodeEngine.getConfig();
ExecutorConfig executorConfig = (ExecutorConfig) config;
return nodeConfig.checkStaticConfigDoesNotExist(nodeConfig.getStaticConfig().getExecutorConfigs(), executorConfig.getName(), executorConfig);
}
Aggregations