use of com.hazelcast.spi.impl.NodeEngine 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);
}
use of com.hazelcast.spi.impl.NodeEngine in project hazelcast by hazelcast.
the class EvictionMaxSizePolicyTest method setTestSizeEstimator.
public static void setTestSizeEstimator(IMap map, final long oneEntryHeapCostInBytes) {
final MapProxyImpl mapProxy = (MapProxyImpl) map;
final MapService mapService = (MapService) mapProxy.getService();
final MapServiceContext mapServiceContext = mapService.getMapServiceContext();
final NodeEngine nodeEngine = mapServiceContext.getNodeEngine();
final IPartitionService partitionService = nodeEngine.getPartitionService();
for (int i = 0; i < partitionService.getPartitionCount(); i++) {
final Address owner = partitionService.getPartitionOwner(i);
if (nodeEngine.getThisAddress().equals(owner)) {
final PartitionContainer container = mapServiceContext.getPartitionContainer(i);
if (container == null) {
continue;
}
final RecordStore recordStore = container.getRecordStore(map.getName());
final DefaultRecordStore defaultRecordStore = (DefaultRecordStore) recordStore;
defaultRecordStore.setSizeEstimator(new EntryCostEstimator() {
long size;
@Override
public long getEstimate() {
return size;
}
@Override
public void adjustEstimateBy(long size) {
this.size += size;
}
@Override
public long calculateValueCost(Object record) {
if (record == null) {
return 0L;
}
return oneEntryHeapCostInBytes;
}
@Override
public long calculateEntryCost(Object key, Object record) {
if (record == null) {
return 0L;
}
return 2 * oneEntryHeapCostInBytes;
}
@Override
public void reset() {
size = 0;
}
});
}
}
}
use of com.hazelcast.spi.impl.NodeEngine in project hazelcast by hazelcast.
the class MapMergePolicyQuickTest method testPutIfAbsentMapMergePolicy.
@Test
public void testPutIfAbsentMapMergePolicy() {
HazelcastInstance instance = createHazelcastInstance(getConfig());
String name = randomString();
IMap<String, String> map = instance.getMap(name);
MapServiceContext mapServiceContext = getMapServiceContext(instance);
Data dataKey = mapServiceContext.toData("key");
Data dataValue = mapServiceContext.toData("value1");
Data dataValue2 = mapServiceContext.toData("value2");
RecordStore recordStore = mapServiceContext.getRecordStore(getPartitionId(instance, "key"), name);
recordStore.beforeOperation();
NodeEngine nodeEngine = mapServiceContext.getNodeEngine();
SplitBrainMergePolicyProvider mergePolicyProvider = nodeEngine.getSplitBrainMergePolicyProvider();
SplitBrainMergePolicy mergePolicy = mergePolicyProvider.getMergePolicy(PutIfAbsentMergePolicy.class.getName());
SimpleEntryView<Data, Data> initialEntry = new SimpleEntryView<>(dataKey, dataValue);
recordStore.merge(createMergingEntry(nodeEngine.getSerializationService(), initialEntry), mergePolicy, CallerProvenance.NOT_WAN);
SimpleEntryView<Data, Data> mergingEntry = new SimpleEntryView<>(dataKey, dataValue2);
recordStore.merge(createMergingEntry(nodeEngine.getSerializationService(), mergingEntry), mergePolicy, CallerProvenance.NOT_WAN);
assertEquals("value1", map.get("key"));
recordStore.afterOperation();
}
use of com.hazelcast.spi.impl.NodeEngine in project hazelcast by hazelcast.
the class EntryEventDataCacheTest method parameters.
@Parameterized.Parameters(name = "{0}")
public static Collection<Object[]> parameters() {
// setup mock MapServiceContext & NodeEngine, required by FilteringStrategy's
MapServiceContext mapServiceContext = mock(MapServiceContext.class);
NodeEngine mockNodeEngine = mock(NodeEngine.class);
when(mockNodeEngine.getThisAddress()).thenReturn(ADDRESS);
when(mapServiceContext.toData(anyObject())).thenReturn(new HeapData());
when(mapServiceContext.getNodeEngine()).thenReturn(mockNodeEngine);
return Arrays.asList(new Object[][] { { new DefaultEntryEventFilteringStrategy(null, mapServiceContext) }, { new QueryCacheNaturalFilteringStrategy(null, mapServiceContext) } });
}
use of com.hazelcast.spi.impl.NodeEngine in project hazelcast by hazelcast.
the class QueryUtilsTest method testVersionMismatch.
@Test
public void testVersionMismatch() {
HazelcastInstance member = factory.newHazelcastInstance();
NodeEngine nodeEngine = Accessors.getNodeEngineImpl(member);
String memberId = nodeEngine.getLocalMember().getUuid().toString();
String memberVersion = nodeEngine.getLocalMember().getVersion().toString();
try {
QueryUtils.createPartitionMap(nodeEngine, new MemberVersion(0, 0, 0), false);
fail("Must fail");
} catch (QueryException e) {
assertEquals(SqlErrorCode.GENERIC, e.getCode());
assertEquals("Cannot execute SQL query when members have different versions (make sure that all members " + "have the same version) {localMemberId=" + memberId + ", localMemberVersion=0.0.0, remoteMemberId=" + memberId + ", remoteMemberVersion=" + memberVersion + "}", e.getMessage());
}
}
Aggregations