use of com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl in project hazelcast by hazelcast.
the class EntryProcessorOffloadableTest method testHeartBeatsComingWhenEntryProcessorOffloaded.
/**
* <pre>
* Given: Operation heartbeats are sent four times per {@link ClusterProperty#OPERATION_CALL_TIMEOUT_MILLIS}
* (see {@link InvocationMonitor#getHeartbeatBroadcastPeriodMillis()})
* When: An offloaded EntryProcessor takes a long time to run.
* Then: Heartbeats are still coming while the task is offloaded.
* </pre>
*/
@Test
@Category(SlowTest.class)
public void testHeartBeatsComingWhenEntryProcessorOffloaded() {
/* Shut down the cluster since we want to use a different
* OPERATION_CALL_TIMEOUT_MILLIS value in this test. */
shutdownNodeFactory();
int heartbeatsIntervalSec = 15;
Config config = getConfig();
config.getProperties().setProperty(ClusterProperty.OPERATION_CALL_TIMEOUT_MILLIS.getName(), String.valueOf(heartbeatsIntervalSec * 4 * 1000));
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
instances = factory.newInstances(config);
final String key = generateKeyOwnedBy(instances[1]);
String offloadableStartTimeRefName = "offloadableStartTimeRefName";
String exitLatchName = "exitLatchName";
IAtomicLong offloadableStartedTimeRef = instances[0].getCPSubsystem().getAtomicLong(offloadableStartTimeRefName);
ICountDownLatch exitLatch = instances[0].getCPSubsystem().getCountDownLatch(exitLatchName);
exitLatch.trySetCount(1);
TimestampedSimpleValue givenValue = new TimestampedSimpleValue(1);
final IMap<String, TimestampedSimpleValue> map = instances[0].getMap(MAP_NAME);
map.put(key, givenValue);
final Address instance1Address = instances[1].getCluster().getLocalMember().getAddress();
final List<Long> heartBeatTimestamps = new LinkedList<>();
Thread hbMonitorThread = new Thread(() -> {
NodeEngine nodeEngine = getNodeEngineImpl(instances[0]);
OperationServiceImpl osImpl = (OperationServiceImpl) nodeEngine.getOperationService();
Map<Address, AtomicLong> heartBeats = osImpl.getInvocationMonitor().getHeartbeatPerMember();
long lastbeat = Long.MIN_VALUE;
while (!Thread.currentThread().isInterrupted()) {
AtomicLong timestamp = heartBeats.get(instance1Address);
if (timestamp != null) {
long newlastbeat = timestamp.get();
if (lastbeat != newlastbeat) {
lastbeat = newlastbeat;
long offloadableStartTime = offloadableStartedTimeRef.get();
if (offloadableStartTime != 0 && offloadableStartTime < newlastbeat) {
heartBeatTimestamps.add(newlastbeat);
exitLatch.countDown();
}
}
}
HazelcastTestSupport.sleepMillis(100);
}
});
final int secondsToRun = 55;
try {
hbMonitorThread.start();
map.executeOnKey(key, new TimeConsumingOffloadableTask(secondsToRun, offloadableStartTimeRefName, exitLatchName));
} finally {
hbMonitorThread.interrupt();
}
int heartBeatCount = 0;
TimestampedSimpleValue updatedValue = map.get(key);
for (long heartBeatTimestamp : heartBeatTimestamps) {
if (heartBeatTimestamp > updatedValue.processStart && heartBeatTimestamp < updatedValue.processEnd) {
heartBeatCount++;
}
}
assertTrue("Heartbeats should be received while offloadable entry processor is running. " + "Observed: " + heartBeatTimestamps + " EP start: " + updatedValue.processStart + " end: " + updatedValue.processEnd, heartBeatCount > 0);
}
use of com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl in project hazelcast by hazelcast.
the class AdvancedClusterStateTest method partitionInvocation_shouldFail_whenPartitionsNotAssigned_whenMigrationNotAllowed.
private void partitionInvocation_shouldFail_whenPartitionsNotAssigned_whenMigrationNotAllowed(ClusterState state) throws InterruptedException {
Config config = new Config();
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
HazelcastInstance[] instances = factory.newInstances(config);
HazelcastInstance hz2 = instances[1];
HazelcastInstance hz3 = instances[2];
changeClusterStateEventually(hz2, state);
OperationServiceImpl operationService = getNode(hz3).getNodeEngine().getOperationService();
Operation op = new AddAndGetOperation(randomName(), 1);
Future<Long> future = operationService.invokeOnPartition(LongRegisterService.SERVICE_NAME, op, 1);
exception.expect(IllegalStateException.class);
try {
future.get();
} catch (ExecutionException e) {
// IllegalStateException should be cause of ExecutionException.
throw ExceptionUtil.rethrow(e);
}
}
use of com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl in project hazelcast by hazelcast.
the class ReadMetricsOperationTest method testMetricsPresent_map.
@Test
public void testMetricsPresent_map() {
Config config = new Config();
HazelcastInstance hzInstance = createHazelcastInstance(config);
IMap<Object, Object> map = hzInstance.getMap("map");
map.put("key", "value");
NodeEngineImpl nodeEngine = getNode(hzInstance).getNodeEngine();
OperationServiceImpl operationService = nodeEngine.getOperationService();
AtomicLong nextSequence = new AtomicLong();
assertTrueEventually(() -> {
long sequence = nextSequence.get();
ReadMetricsOperation readMetricsOperation = new ReadMetricsOperation(sequence);
InternalCompletableFuture<RingbufferSlice<Map.Entry<Long, byte[]>>> future = operationService.invokeOnTarget(MetricsService.SERVICE_NAME, readMetricsOperation, nodeEngine.getThisAddress());
RingbufferSlice<Map.Entry<Long, byte[]>> ringbufferSlice = future.get();
MetricsResultSet metricsResultSet = new MetricsResultSet(ringbufferSlice.nextSequence(), ringbufferSlice.elements());
nextSequence.set(metricsResultSet.nextSequence());
boolean mapMetric = false;
List<Map.Entry<Long, byte[]>> collections = metricsResultSet.collections();
MetricKeyConsumer metricConsumer = new MetricKeyConsumer();
for (Map.Entry<Long, byte[]> entry : collections) {
MetricsCompressor.extractMetrics(entry.getValue(), metricConsumer);
}
assertTrue(metricConsumer.mapMetric);
});
}
use of com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl in project hazelcast by hazelcast.
the class StaleReadDuringMigrationTest method invokeOperation.
private InternalCompletableFuture<Boolean> invokeOperation(final Config config) {
final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(1);
final HazelcastInstance instance = factory.newHazelcastInstance(config);
warmUpPartitions(instance);
final int partitionId = 0;
final InternalPartitionServiceImpl partitionService = (InternalPartitionServiceImpl) getPartitionService(instance);
final InternalPartitionImpl partition = (InternalPartitionImpl) partitionService.getPartition(partitionId);
partition.setMigrating();
final OperationServiceImpl operationService = getOperationService(instance);
final InvocationBuilder invocationBuilder = operationService.createInvocationBuilder(InternalPartitionService.SERVICE_NAME, new DummyOperation(), partitionId);
return invocationBuilder.invoke();
}
use of com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl in project hazelcast by hazelcast.
the class MigrationCommitServiceTest method setup.
@Before
public void setup() throws Exception {
blockMigrationStartLatch = new CountDownLatch(1);
factory = createHazelcastInstanceFactory(NODE_COUNT);
instances = factory.newInstances(createConfig(), NODE_COUNT);
warmUpPartitions(instances);
waitAllForSafeState(instances);
OperationServiceImpl operationService = getOperationService(instances[0]);
for (int partitionId = 0; partitionId < PARTITION_COUNT; partitionId++) {
operationService.invokeOnPartition(null, new TestIncrementOperation(), partitionId).get();
}
assertTrueEventually(new AssertTask() {
@Override
public void run() {
for (int partitionId = 0; partitionId < PARTITION_COUNT; partitionId++) {
InternalPartitionService partitionService = getPartitionService(instances[0]);
InternalPartition partition = partitionService.getPartition(partitionId);
// given that NODE_COUNT < BACKUP_COUNT, there can be at most
// NODE_COUNT replicas overall.
final int replicasCount = Math.min(BACKUP_COUNT + 1, NODE_COUNT);
for (int i = 0; i < replicasCount; i++) {
// replica assignment should complete, so that when we later
// reference a replica, we do not get NPE.
Address replicaAddress = partition.getReplicaAddress(i);
assertNotNull(replicaAddress);
TestMigrationAwareService service = getService(replicaAddress);
assertNotNull(service.get(partitionId));
}
}
}
});
for (HazelcastInstance instance : instances) {
TestMigrationAwareService service = getNodeEngineImpl(instance).getService(TestMigrationAwareService.SERVICE_NAME);
service.clearEvents();
}
}
Aggregations