Search in sources :

Example 36 with OperationServiceImpl

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);
}
Also used : Address(com.hazelcast.cluster.Address) MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) ICountDownLatch(com.hazelcast.cp.ICountDownLatch) LinkedList(java.util.LinkedList) NodeEngine(com.hazelcast.spi.impl.NodeEngine) IAtomicLong(com.hazelcast.cp.IAtomicLong) AtomicLong(java.util.concurrent.atomic.AtomicLong) IAtomicLong(com.hazelcast.cp.IAtomicLong) AtomicLong(java.util.concurrent.atomic.AtomicLong) IAtomicLong(com.hazelcast.cp.IAtomicLong) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) Category(org.junit.experimental.categories.Category) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 37 with OperationServiceImpl

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);
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) AddAndGetOperation(com.hazelcast.internal.longregister.operations.AddAndGetOperation) Config(com.hazelcast.config.Config) AddAndGetOperation(com.hazelcast.internal.longregister.operations.AddAndGetOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) ExecutionException(java.util.concurrent.ExecutionException) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl)

Example 38 with OperationServiceImpl

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);
    });
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) RingbufferSlice(com.hazelcast.internal.metrics.managementcenter.ConcurrentArrayRingbuffer.RingbufferSlice) Config(com.hazelcast.config.Config) ReadMetricsOperation(com.hazelcast.internal.metrics.managementcenter.ReadMetricsOperation) MetricsResultSet(com.hazelcast.internal.metrics.managementcenter.MetricsResultSet) AtomicLong(java.util.concurrent.atomic.AtomicLong) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AtomicLong(java.util.concurrent.atomic.AtomicLong) Map(java.util.Map) IMap(com.hazelcast.map.IMap) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 39 with OperationServiceImpl

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();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) InternalPartitionImpl(com.hazelcast.internal.partition.impl.InternalPartitionImpl) InvocationBuilder(com.hazelcast.spi.impl.operationservice.InvocationBuilder) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl)

Example 40 with OperationServiceImpl

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();
    }
}
Also used : TestMigrationAwareService(com.hazelcast.internal.partition.service.TestMigrationAwareService) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.cluster.Address) Accessors.getAddress(com.hazelcast.test.Accessors.getAddress) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) AssertTask(com.hazelcast.test.AssertTask) TestIncrementOperation(com.hazelcast.internal.partition.service.TestIncrementOperation) InternalPartition(com.hazelcast.internal.partition.InternalPartition) CountDownLatch(java.util.concurrent.CountDownLatch) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) Before(org.junit.Before)

Aggregations

OperationServiceImpl (com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl)70 Test (org.junit.Test)29 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)26 QuickTest (com.hazelcast.test.annotation.QuickTest)25 Address (com.hazelcast.cluster.Address)22 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)16 HazelcastInstance (com.hazelcast.core.HazelcastInstance)15 Operation (com.hazelcast.spi.impl.operationservice.Operation)12 PartitionIdSet (com.hazelcast.internal.util.collection.PartitionIdSet)11 IndexIterationPointer (com.hazelcast.internal.iteration.IndexIterationPointer)10 MapFetchIndexOperationResult (com.hazelcast.map.impl.operation.MapFetchIndexOperation.MapFetchIndexOperationResult)10 Config (com.hazelcast.config.Config)9 ExecutionException (java.util.concurrent.ExecutionException)9 Accessors.getNodeEngineImpl (com.hazelcast.test.Accessors.getNodeEngineImpl)8 AssertTask (com.hazelcast.test.AssertTask)7 CountDownLatch (java.util.concurrent.CountDownLatch)7 Member (com.hazelcast.cluster.Member)5 Data (com.hazelcast.internal.serialization.Data)5 MapService (com.hazelcast.map.impl.MapService)5 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)5