Search in sources :

Example 21 with OperationService

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

the class CachePutAllTest method testPutAll_whenEntryExpiresOnCreate.

@Test
public void testPutAll_whenEntryExpiresOnCreate() {
    Factory<? extends ExpiryPolicy> expiryPolicyFactory = FactoryBuilder.factoryOf(new CreatedExpiryPolicy(Duration.ZERO));
    CacheConfig<String, String> cacheConfig = new CacheConfig<String, String>();
    cacheConfig.setTypes(String.class, String.class);
    cacheConfig.setExpiryPolicyFactory(expiryPolicyFactory);
    cacheConfig.setStatisticsEnabled(true);
    cacheConfig.setBackupCount(1);
    Cache<String, String> cache = createCache(cacheConfig);
    String key = generateKeyOwnedBy(hazelcastInstance);
    // need to count the number of backup failures on backup member
    OperationService operationService = getOperationService(hazelcastInstances[1]);
    MetricsRegistry metricsRegistry = getMetricsRegistry(hazelcastInstances[1]);
    assertEquals(0L, OperationServiceAccessor.getFailedBackupsCount(hazelcastInstances[1]).get());
    Map<String, String> entries = new HashMap<String, String>();
    entries.put(key, randomString());
    cache.putAll(entries);
    assertNull(cache.get(key));
    // force collect metrics
    metricsRegistry.provideMetrics(operationService);
    assertEquals(0L, OperationServiceAccessor.getFailedBackupsCount(hazelcastInstances[1]).get());
}
Also used : MetricsRegistry(com.hazelcast.internal.metrics.MetricsRegistry) Accessors.getMetricsRegistry(com.hazelcast.test.Accessors.getMetricsRegistry) HashMap(java.util.HashMap) CreatedExpiryPolicy(javax.cache.expiry.CreatedExpiryPolicy) Accessors.getOperationService(com.hazelcast.test.Accessors.getOperationService) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) CacheConfig(com.hazelcast.config.CacheConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 22 with OperationService

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

the class ConnectedClientOperationTest method testGetConnectedClientsOperation_WhenMoreThanZeroClientConnects.

@Test
public void testGetConnectedClientsOperation_WhenMoreThanZeroClientConnects() throws Exception {
    HazelcastInstance instance = factory.newHazelcastInstance();
    factory.newHazelcastClient();
    factory.newHazelcastClient();
    Node node = getNode(instance);
    Operation operation = new GetConnectedClientsOperation();
    OperationService operationService = node.nodeEngine.getOperationService();
    Future<Map<String, String>> future = operationService.invokeOnTarget(ClientEngineImpl.SERVICE_NAME, operation, node.address);
    Map<String, String> clients = future.get();
    assertEquals(2, clients.size());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Node(com.hazelcast.instance.impl.Node) Accessors.getNode(com.hazelcast.test.Accessors.getNode) GetConnectedClientsOperation(com.hazelcast.client.impl.operations.GetConnectedClientsOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) GetConnectedClientsOperation(com.hazelcast.client.impl.operations.GetConnectedClientsOperation) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) Map(java.util.Map) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 23 with OperationService

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

the class InternalPartitionServiceImpl method sendPartitionRuntimeState.

void sendPartitionRuntimeState(Address target) {
    if (!isLocalMemberMaster()) {
        return;
    }
    assert partitionStateManager.isInitialized();
    PartitionRuntimeState partitionState = createPartitionStateInternal();
    assert partitionState != null;
    if (logger.isFineEnabled()) {
        logger.fine("Sending partition state, stamp: " + partitionState.getStamp() + ", to " + target);
    }
    OperationService operationService = nodeEngine.getOperationService();
    PartitionStateOperation op = new PartitionStateOperation(partitionState, true);
    operationService.invokeOnTarget(SERVICE_NAME, op, target);
}
Also used : PartitionRuntimeState(com.hazelcast.internal.partition.PartitionRuntimeState) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) FetchPartitionStateOperation(com.hazelcast.internal.partition.operation.FetchPartitionStateOperation) PartitionStateOperation(com.hazelcast.internal.partition.operation.PartitionStateOperation)

Example 24 with OperationService

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

the class InternalPartitionServiceImpl method checkClusterPartitionRuntimeStates.

void checkClusterPartitionRuntimeStates() {
    if (!partitionStateManager.isInitialized()) {
        return;
    }
    if (!isLocalMemberMaster()) {
        return;
    }
    if (!areMigrationTasksAllowed()) {
        // migration is disabled because of a member leave, wait till enabled!
        return;
    }
    long stamp = getPartitionStateStamp();
    if (logger.isFineEnabled()) {
        logger.fine("Checking partition state, stamp: " + stamp);
    }
    OperationService operationService = nodeEngine.getOperationService();
    Collection<Member> members = node.clusterService.getMembers();
    for (Member member : members) {
        if (!member.localMember()) {
            PartitionStateCheckOperation op = new PartitionStateCheckOperation(stamp);
            InvocationFuture<Boolean> future = operationService.invokeOnTarget(SERVICE_NAME, op, member.getAddress());
            future.whenCompleteAsync((response, throwable) -> {
                if (throwable == null) {
                    if (!Boolean.TRUE.equals(response)) {
                        logger.fine(member + " has a stale partition state. Will send the most recent partition state now.");
                        sendPartitionRuntimeState(member.getAddress());
                    }
                } else {
                    logger.fine("Failure while checking partition state on " + member, throwable);
                    sendPartitionRuntimeState(member.getAddress());
                }
            });
        }
    }
}
Also used : PartitionStateCheckOperation(com.hazelcast.internal.partition.operation.PartitionStateCheckOperation) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Member(com.hazelcast.cluster.Member)

Example 25 with OperationService

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

the class BasicRecordStoreLoader method sendOperation.

/**
 * Invokes an operation to put the provided key-value pairs to the partition
 * record store.
 *
 * @param loadingSequence the list of serialised key-value-(expirationTime)
 *                        sequences
 * @return the future representing the pending completion of the put operation
 */
private Future<?> sendOperation(List<Data> loadingSequence) {
    OperationService operationService = mapServiceContext.getNodeEngine().getOperationService();
    NodeEngine nodeEngine = mapServiceContext.getNodeEngine();
    Operation operation = createOperation(loadingSequence);
    operation.setNodeEngine(nodeEngine);
    operation.setPartitionId(partitionId);
    OperationAccessor.setCallerAddress(operation, nodeEngine.getThisAddress());
    operation.setCallerUuid(nodeEngine.getLocalMember().getUuid());
    operation.setServiceName(MapService.SERVICE_NAME);
    return operationService.invokeOnPartition(MapService.SERVICE_NAME, operation, partitionId);
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) Operation(com.hazelcast.spi.impl.operationservice.Operation) RemoveFromLoadAllOperation(com.hazelcast.map.impl.operation.RemoveFromLoadAllOperation)

Aggregations

OperationService (com.hazelcast.spi.impl.operationservice.OperationService)140 Operation (com.hazelcast.spi.impl.operationservice.Operation)55 Test (org.junit.Test)54 HazelcastInstance (com.hazelcast.core.HazelcastInstance)46 QuickTest (com.hazelcast.test.annotation.QuickTest)41 Accessors.getOperationService (com.hazelcast.test.Accessors.getOperationService)40 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)40 Address (com.hazelcast.cluster.Address)31 NodeEngine (com.hazelcast.spi.impl.NodeEngine)31 InternalCompletableFuture (com.hazelcast.spi.impl.InternalCompletableFuture)24 Future (java.util.concurrent.Future)24 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)23 Config (com.hazelcast.config.Config)22 Member (com.hazelcast.cluster.Member)21 Data (com.hazelcast.internal.serialization.Data)12 SlowTest (com.hazelcast.test.annotation.SlowTest)12 ClusterService (com.hazelcast.internal.cluster.ClusterService)9 ILogger (com.hazelcast.logging.ILogger)7 ArrayList (java.util.ArrayList)7 IPartitionService (com.hazelcast.internal.partition.IPartitionService)6