Search in sources :

Example 46 with OperationServiceImpl

use of com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl in project hazelcast by hazelcast.

the class CacheDestroyTest method test_cacheDestroyOperation.

@Test
public void test_cacheDestroyOperation() {
    final String CACHE_NAME = "MyCache";
    final String FULL_CACHE_NAME = HazelcastCacheManager.CACHE_MANAGER_PREFIX + CACHE_NAME;
    final CountDownLatch cacheProxyCreatedLatch = new CountDownLatch(INSTANCE_COUNT);
    for (HazelcastInstance hz : hazelcastInstances) {
        hz.addDistributedObjectListener(new CacheProxyListener(cacheProxyCreatedLatch));
    }
    CachingProvider cachingProvider = createServerCachingProvider(getHazelcastInstance());
    CacheManager cacheManager = cachingProvider.getCacheManager();
    cacheManager.createCache(CACHE_NAME, new CacheConfig());
    NodeEngineImpl nodeEngine1 = getNode(getHazelcastInstance()).getNodeEngine();
    final ICacheService cacheService1 = nodeEngine1.getService(ICacheService.SERVICE_NAME);
    OperationServiceImpl operationService1 = nodeEngine1.getOperationService();
    NodeEngineImpl nodeEngine2 = getNode(hazelcastInstances[1]).getNodeEngine();
    final ICacheService cacheService2 = nodeEngine2.getService(ICacheService.SERVICE_NAME);
    assertNotNull(cacheService1.getCacheConfig(FULL_CACHE_NAME));
    assertNotNull(cacheService2.getCacheConfig(FULL_CACHE_NAME));
    // wait for the latch to ensure proxy registration events have been processed (otherwise
    // the cache config may be added on a member after having been removed by CacheDestroyOp)
    assertOpenEventually("A cache proxy should have been created on each instance, latch count was " + cacheProxyCreatedLatch.getCount(), cacheProxyCreatedLatch);
    // Invoke on single node and the operation is also forward to others nodes by the operation itself
    operationService1.invokeOnTarget(ICacheService.SERVICE_NAME, new CacheDestroyOperation(FULL_CACHE_NAME), nodeEngine1.getThisAddress());
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertNull(cacheService1.getCacheConfig(FULL_CACHE_NAME));
            assertNull(cacheService2.getCacheConfig(FULL_CACHE_NAME));
        }
    });
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) CountDownLatch(java.util.concurrent.CountDownLatch) CacheException(javax.cache.CacheException) ExecutionException(java.util.concurrent.ExecutionException) CacheDestroyOperation(com.hazelcast.cache.impl.operation.CacheDestroyOperation) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ICacheService(com.hazelcast.cache.impl.ICacheService) CacheManager(javax.cache.CacheManager) AssertTask(com.hazelcast.test.AssertTask) CacheConfig(com.hazelcast.config.CacheConfig) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) CachingProvider(javax.cache.spi.CachingProvider) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 47 with OperationServiceImpl

use of com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl in project hazelcast by hazelcast.

the class ClientListenersTest method testEntryMergeListener_withPortableNotRegisteredInNode.

@Test
public void testEntryMergeListener_withPortableNotRegisteredInNode() throws Exception {
    final IMap<Object, Object> map = client.getMap(randomMapName());
    final CountDownLatch latch = new CountDownLatch(1);
    map.addEntryListener(new EntryMergedListener<Object, Object>() {

        @Override
        public void entryMerged(EntryEvent<Object, Object> event) {
            latch.countDown();
        }
    }, true);
    Node node = getNode(server);
    NodeEngineImpl nodeEngine = node.nodeEngine;
    OperationServiceImpl operationService = nodeEngine.getOperationService();
    SerializationService serializationService = getSerializationService(server);
    Data key = serializationService.toData(1);
    Data value = serializationService.toData(new ClientRegressionWithMockNetworkTest.SamplePortable(1));
    SplitBrainMergeTypes.MapMergeTypes mergingEntry = createMergingEntry(serializationService, key, value, Mockito.mock(Record.class), ExpiryMetadata.NULL);
    Operation op = new MergeOperation(map.getName(), Collections.singletonList(mergingEntry), new PassThroughMergePolicy<>(), false);
    int partitionId = nodeEngine.getPartitionService().getPartitionId(key);
    operationService.invokeOnPartition(MapService.SERVICE_NAME, op, partitionId);
    assertOpenEventually(latch);
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) MergeOperation(com.hazelcast.map.impl.operation.MergeOperation) Node(com.hazelcast.instance.impl.Node) Accessors.getNode(com.hazelcast.test.Accessors.getNode) SerializationService(com.hazelcast.internal.serialization.SerializationService) Accessors.getSerializationService(com.hazelcast.test.Accessors.getSerializationService) Data(com.hazelcast.internal.serialization.Data) Operation(com.hazelcast.spi.impl.operationservice.Operation) MergeOperation(com.hazelcast.map.impl.operation.MergeOperation) CountDownLatch(java.util.concurrent.CountDownLatch) Record(com.hazelcast.map.impl.record.Record) SplitBrainMergeTypes(com.hazelcast.spi.merge.SplitBrainMergeTypes) 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 48 with OperationServiceImpl

use of com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl in project hazelcast by hazelcast.

the class ClientDisconnectTest method assertNonEmptyPendingInvocationAndWaitSet.

private void assertNonEmptyPendingInvocationAndWaitSet(HazelcastInstance server) {
    NodeEngineImpl nodeEngine = getNodeEngineImpl(server);
    OperationServiceImpl operationService = (OperationServiceImpl) nodeEngine.getOperationService();
    final InvocationRegistry invocationRegistry = operationService.getInvocationRegistry();
    final OperationParkerImpl operationParker = (OperationParkerImpl) nodeEngine.getOperationParker();
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            assertFalse(invocationRegistry.entrySet().isEmpty());
        }
    });
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            assertTrue(operationParker.getTotalParkedOperationCount() > 0);
        }
    });
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Accessors.getNodeEngineImpl(com.hazelcast.test.Accessors.getNodeEngineImpl) AssertTask(com.hazelcast.test.AssertTask) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) InvocationRegistry(com.hazelcast.spi.impl.operationservice.impl.InvocationRegistry) OperationParkerImpl(com.hazelcast.spi.impl.operationparker.impl.OperationParkerImpl)

Example 49 with OperationServiceImpl

use of com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl in project hazelcast by hazelcast.

the class OperationFactoryWrapperTest method testOperationSeesActualCallersUUID.

/**
 * OperationFactoryWrapper gets a UUID and sets it to its created operations.
 * This test ensures UUID doesn't change through the operation system.
 */
@Test
public void testOperationSeesActualCallersUUID() throws Exception {
    HazelcastInstance hz = createHazelcastInstance();
    OperationServiceImpl operationService = getOperationService(hz);
    UUID expectedCallersUUID = UUID.randomUUID();
    GetCallersUUIDOperationFactory operationFactory = new GetCallersUUIDOperationFactory();
    OperationFactoryWrapper wrapper = new OperationFactoryWrapper(operationFactory, expectedCallersUUID);
    int partitionId = 0;
    Map<Integer, Object> responses = operationService.invokeOnPartitions(SERVICE_NAME, wrapper, singletonList(partitionId));
    UUID actualCallersUUID = (UUID) responses.get(partitionId);
    assertEquals("Callers UUID should not be changed", expectedCallersUUID, actualCallersUUID);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) UUID(java.util.UUID) 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 50 with OperationServiceImpl

use of com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl in project hazelcast by hazelcast.

the class AbstractMapQueryMessageTask method createInvocationsForMissingPartitions.

private void createInvocationsForMissingPartitions(PartitionIdSet missingPartitionsList, List<Future> futures, Predicate predicate) {
    final OperationServiceImpl operationService = nodeEngine.getOperationService();
    MapService mapService = nodeEngine.getService(getServiceName());
    MapServiceContext mapServiceContext = mapService.getMapServiceContext();
    Query query = buildQuery(predicate);
    PrimitiveIterator.OfInt missingPartitionIterator = missingPartitionsList.intIterator();
    missingPartitionIterator.forEachRemaining((IntConsumer) partitionId -> {
        MapOperation queryPartitionOperation = createQueryPartitionOperation(query, mapServiceContext);
        queryPartitionOperation.setPartitionId(partitionId);
        try {
            Future future = operationService.invokeOnPartition(SERVICE_NAME, queryPartitionOperation, partitionId);
            futures.add(future);
        } catch (Throwable t) {
            throw rethrow(t);
        }
    });
}
Also used : Query(com.hazelcast.map.impl.query.Query) PartitionPredicate(com.hazelcast.query.PartitionPredicate) Member(com.hazelcast.cluster.Member) IntConsumer(java.util.function.IntConsumer) QueryResultSizeExceededException(com.hazelcast.map.QueryResultSizeExceededException) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) ExceptionUtil.rethrow(com.hazelcast.internal.util.ExceptionUtil.rethrow) Aggregator(com.hazelcast.aggregation.Aggregator) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) AbstractCallableMessageTask(com.hazelcast.client.impl.protocol.task.AbstractCallableMessageTask) DATA_MEMBER_SELECTOR(com.hazelcast.cluster.memberselector.MemberSelectors.DATA_MEMBER_SELECTOR) Operation(com.hazelcast.spi.impl.operationservice.Operation) ActionConstants(com.hazelcast.security.permission.ActionConstants) LinkedList(java.util.LinkedList) Predicate(com.hazelcast.query.Predicate) QueryException(com.hazelcast.query.QueryException) HazelcastException(com.hazelcast.core.HazelcastException) MapOperation(com.hazelcast.map.impl.operation.MapOperation) Connection(com.hazelcast.internal.nio.Connection) SetUtil(com.hazelcast.internal.util.SetUtil) Collection(java.util.Collection) MapService(com.hazelcast.map.impl.MapService) Result(com.hazelcast.map.impl.query.Result) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) Node(com.hazelcast.instance.impl.Node) PrimitiveIterator(java.util.PrimitiveIterator) ExecutionException(java.util.concurrent.ExecutionException) SERVICE_NAME(com.hazelcast.map.impl.MapService.SERVICE_NAME) List(java.util.List) Permission(java.security.Permission) IterationType(com.hazelcast.internal.util.IterationType) Projection(com.hazelcast.projection.Projection) PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) MapPermission(com.hazelcast.security.permission.MapPermission) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) Query(com.hazelcast.map.impl.query.Query) PrimitiveIterator(java.util.PrimitiveIterator) Future(java.util.concurrent.Future) MapService(com.hazelcast.map.impl.MapService) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) MapOperation(com.hazelcast.map.impl.operation.MapOperation)

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