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());
}
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);
}
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);
}
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());
}
}
}
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);
}
Aggregations