Search in sources :

Example 71 with NodeEngine

use of com.hazelcast.spi.impl.NodeEngine in project hazelcast by hazelcast.

the class TransactionLogTest method prepare_partitionSpecificRecord.

@Test
public void prepare_partitionSpecificRecord() throws Exception {
    OperationService operationService = mock(OperationService.class);
    NodeEngine nodeEngine = mock(NodeEngine.class);
    when(nodeEngine.getOperationService()).thenReturn(operationService);
    TransactionLog log = new TransactionLog();
    TransactionLogRecord partitionRecord = mock(TransactionLogRecord.class);
    Operation partitionOperation = new DummyPartitionOperation();
    when(partitionRecord.newPrepareOperation()).thenReturn(partitionOperation);
    log.add(partitionRecord);
    log.prepare(nodeEngine);
    verify(operationService, times(1)).invokeOnPartition(partitionOperation.getServiceName(), partitionOperation, partitionOperation.getPartitionId());
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) Operation(com.hazelcast.spi.impl.operationservice.Operation) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 72 with NodeEngine

use of com.hazelcast.spi.impl.NodeEngine in project hazelcast by hazelcast.

the class TransactionLogTest method prepare_targetAwareRecord.

@Test
public void prepare_targetAwareRecord() throws Exception {
    OperationService operationService = mock(OperationService.class);
    NodeEngine nodeEngine = mock(NodeEngine.class);
    when(nodeEngine.getOperationService()).thenReturn(operationService);
    TransactionLog log = new TransactionLog();
    Address target = new Address(InetAddress.getLocalHost(), 5000);
    TargetAwareTransactionLogRecord targetRecord = mock(TargetAwareTransactionLogRecord.class);
    when(targetRecord.getTarget()).thenReturn(target);
    DummyTargetOperation targetOperation = new DummyTargetOperation();
    when(targetRecord.newPrepareOperation()).thenReturn(targetOperation);
    log.add(targetRecord);
    log.prepare(nodeEngine);
    verify(operationService, times(1)).invokeOnTarget(targetOperation.getServiceName(), targetOperation, target);
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) Address(com.hazelcast.cluster.Address) InetAddress(java.net.InetAddress) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 73 with NodeEngine

use of com.hazelcast.spi.impl.NodeEngine in project hazelcast by hazelcast.

the class TransactionLogTest method rollback_targetAwareRecord.

@Test
public void rollback_targetAwareRecord() throws Exception {
    OperationService operationService = mock(OperationService.class);
    NodeEngine nodeEngine = mock(NodeEngine.class);
    when(nodeEngine.getOperationService()).thenReturn(operationService);
    TransactionLog log = new TransactionLog();
    Address target = new Address(InetAddress.getLocalHost(), 5000);
    TargetAwareTransactionLogRecord targetRecord = mock(TargetAwareTransactionLogRecord.class);
    when(targetRecord.getTarget()).thenReturn(target);
    DummyTargetOperation targetOperation = new DummyTargetOperation();
    when(targetRecord.newRollbackOperation()).thenReturn(targetOperation);
    log.add(targetRecord);
    log.rollback(nodeEngine);
    verify(operationService, times(1)).invokeOnTarget(targetOperation.getServiceName(), targetOperation, target);
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) Address(com.hazelcast.cluster.Address) InetAddress(java.net.InetAddress) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 74 with NodeEngine

use of com.hazelcast.spi.impl.NodeEngine in project hazelcast by hazelcast.

the class MapTransactionTest method testGetForUpdate_releasesBackupLock.

@Test
public void testGetForUpdate_releasesBackupLock() {
    Config config = getConfig();
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance1 = factory.newHazelcastInstance(config);
    HazelcastInstance instance2 = factory.newHazelcastInstance(config);
    final String keyOwnedByInstance2 = generateKeyOwnedBy(instance2);
    instance1.executeTransaction(new TransactionalTask<Object>() {

        @Override
        public Object execute(TransactionalTaskContext context) throws TransactionException {
            TransactionalMap<Object, Object> map = context.getMap(randomString());
            map.getForUpdate(keyOwnedByInstance2);
            return null;
        }
    });
    NodeEngine nodeEngine = getNodeEngineImpl(instance1);
    Data keyData = nodeEngine.toData(keyOwnedByInstance2);
    LockSupportService lockService = nodeEngine.getService(LockSupportService.SERVICE_NAME);
    for (LockResource lockResource : lockService.getAllLocks()) {
        if (keyData.equals(lockResource.getKey())) {
            assertEquals(0, lockResource.getLockCount());
        }
    }
}
Also used : TransactionalMap(com.hazelcast.transaction.TransactionalMap) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) TransactionalTaskContext(com.hazelcast.transaction.TransactionalTaskContext) Data(com.hazelcast.internal.serialization.Data) LockSupportService(com.hazelcast.internal.locksupport.LockSupportService) NodeEngine(com.hazelcast.spi.impl.NodeEngine) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TransactionException(com.hazelcast.transaction.TransactionException) LockResource(com.hazelcast.internal.locksupport.LockResource) Mockito.anyObject(org.mockito.Mockito.anyObject) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 75 with NodeEngine

use of com.hazelcast.spi.impl.NodeEngine in project hazelcast by hazelcast.

the class CacheManagerAnswer method answer.

@Override
Object answer(InvocationOnMock invocation, String methodName, Object[] arguments) throws Exception {
    if (arguments.length == 1 && methodName.equals("getCacheByFullName")) {
        String cacheName = (String) arguments[0];
        Object original = getFieldValueReflectively(delegate, "original");
        Object delegateNode = getFieldValueReflectively(original, "node");
        Node node = mock(Node.class, new NodeAnswer(delegateNode));
        NodeEngine nodeEngine = node.getNodeEngine();
        CacheConfig cacheConfig = new CacheConfig(node.getConfig().getCacheConfig(cacheName));
        CacheService cacheService = nodeEngine.getService(CacheService.SERVICE_NAME);
        // we have to create the mock with useConstructor(), otherwise the
        // calls to the AbstractDistributedObject (its base class) won't
        // work properly, since the NodeEngine field is not set (final
        // method calls are not mocked in the used Mockito version)
        Object cacheProxy = invokeForMock(invocation, arguments);
        return mock(CacheProxy.class, withSettings().useConstructor(cacheConfig, nodeEngine, cacheService).defaultAnswer(new CacheProxyAnswer(cacheProxy)));
    } else if (arguments.length == 0) {
        return invoke(invocation);
    }
    throw new UnsupportedOperationException("Method is not implemented in CacheManagerAnswer: " + methodName);
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) Node(com.hazelcast.instance.impl.Node) CacheConfig(com.hazelcast.config.CacheConfig) CacheService(com.hazelcast.cache.impl.CacheService)

Aggregations

NodeEngine (com.hazelcast.spi.impl.NodeEngine)165 Data (com.hazelcast.internal.serialization.Data)48 OperationService (com.hazelcast.spi.impl.operationservice.OperationService)30 Address (com.hazelcast.cluster.Address)22 Test (org.junit.Test)21 ILogger (com.hazelcast.logging.ILogger)20 HazelcastInstance (com.hazelcast.core.HazelcastInstance)18 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)18 QuickTest (com.hazelcast.test.annotation.QuickTest)18 Config (com.hazelcast.config.Config)17 Operation (com.hazelcast.spi.impl.operationservice.Operation)16 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)15 IPartitionService (com.hazelcast.internal.partition.IPartitionService)12 Nonnull (javax.annotation.Nonnull)12 ArrayList (java.util.ArrayList)11 Future (java.util.concurrent.Future)11 Member (com.hazelcast.cluster.Member)10 UUID (java.util.UUID)10 InitializingObject (com.hazelcast.spi.impl.InitializingObject)9 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)9