use of com.hazelcast.instance.Node in project hazelcast by hazelcast.
the class EvictionStrategyTest method evictionPolicySuccessfullyEvaluatedOnSamplingBasedEvictionStrategy.
@Test
public void evictionPolicySuccessfullyEvaluatedOnSamplingBasedEvictionStrategy() {
final int RECORD_COUNT = 100;
final int EXPECTED_EVICTED_COUNT = 1;
final int EXPECTED_EVICTED_RECORD_VALUE = RECORD_COUNT / 2;
Node node = TestUtil.getNode(instance);
SerializationService serializationService = node.getSerializationService();
ICacheService cacheService = node.getNodeEngine().getService(ICacheService.SERVICE_NAME);
CacheContext cacheContext = cacheService.getOrCreateCacheContext("MyCache");
EvictionConfiguration evictionConfig = new EvictionConfiguration() {
@Override
public EvictionStrategyType getEvictionStrategyType() {
return EvictionStrategyType.SAMPLING_BASED_EVICTION;
}
@Override
public EvictionPolicyType getEvictionPolicyType() {
return null;
}
@Override
public String getComparatorClassName() {
return null;
}
@Override
public EvictionPolicyComparator getComparator() {
return null;
}
};
SamplingEvictionStrategy<K, V, S> evictionStrategy = SamplingEvictionStrategy.INSTANCE;
CacheRecordHashMap cacheRecordMap = new CacheRecordHashMap(serializationService, 1000, cacheContext);
CacheObjectRecord expectedEvictedRecord = null;
Data expectedData = null;
for (int i = 0; i < RECORD_COUNT; i++) {
CacheObjectRecord record = new CacheObjectRecord(i, System.currentTimeMillis(), Long.MAX_VALUE);
Data data = serializationService.toData(i);
cacheRecordMap.put(data, record);
if (i == EXPECTED_EVICTED_RECORD_VALUE) {
expectedEvictedRecord = record;
expectedData = data;
}
}
assertNotNull(expectedEvictedRecord);
assertNotNull(expectedData);
final SimpleEvictionCandidate evictionCandidate = new SimpleEvictionCandidate((K) expectedData, (V) expectedEvictedRecord);
// we are testing "EvictionStrategy" in this test, so we mock "EvictionPolicyEvaluator" (it's tested in another test)
EvictionPolicyEvaluator evictionPolicyEvaluator = mock(EvictionPolicyEvaluator.class);
when(evictionPolicyEvaluator.evaluate(Matchers.any(Iterable.class))).thenReturn(Collections.singleton(evictionCandidate));
when(evictionPolicyEvaluator.getEvictionPolicyComparator()).thenReturn(null);
assertEquals(RECORD_COUNT, cacheRecordMap.size());
assertTrue(cacheRecordMap.containsKey(expectedData));
assertTrue(cacheRecordMap.containsValue(expectedEvictedRecord));
int evictedCount = evictionStrategy.evict((S) cacheRecordMap, evictionPolicyEvaluator, EVICT_ALWAYS, NO_LISTENER);
assertEquals(EXPECTED_EVICTED_COUNT, evictedCount);
assertEquals(RECORD_COUNT - EXPECTED_EVICTED_COUNT, cacheRecordMap.size());
assertFalse(cacheRecordMap.containsKey(expectedData));
assertFalse(cacheRecordMap.containsValue(expectedEvictedRecord));
}
use of com.hazelcast.instance.Node in project hazelcast by hazelcast.
the class ClearWanQueuesTest method setUp.
@Before
public void setUp() {
HazelcastInstance hz = createHazelcastInstance();
Node node = getNode(hz);
managementCenterService = node.getManagementCenterService();
}
use of com.hazelcast.instance.Node in project hazelcast by hazelcast.
the class HttpGetCommandProcessor method handleHealthcheck.
private void handleHealthcheck(HttpGetCommand command) {
Node node = textCommandService.getNode();
NodeState nodeState = node.getState();
ClusterServiceImpl clusterService = node.getClusterService();
ClusterState clusterState = clusterService.getClusterState();
int clusterSize = clusterService.getMembers().size();
InternalPartitionService partitionService = node.getPartitionService();
boolean memberStateSafe = partitionService.isMemberStateSafe();
boolean clusterSafe = memberStateSafe && !partitionService.hasOnGoingMigration();
long migrationQueueSize = partitionService.getMigrationQueueSize();
StringBuilder res = new StringBuilder();
res.append("Hazelcast::NodeState=").append(nodeState).append("\n");
res.append("Hazelcast::ClusterState=").append(clusterState).append("\n");
res.append("Hazelcast::ClusterSafe=").append(Boolean.toString(clusterSafe).toUpperCase()).append("\n");
res.append("Hazelcast::MigrationQueueSize=").append(migrationQueueSize).append("\n");
res.append("Hazelcast::ClusterSize=").append(clusterSize).append("\n");
command.setResponse(MIME_TEXT_PLAIN, stringToBytes(res.toString()));
}
use of com.hazelcast.instance.Node in project hazelcast by hazelcast.
the class HttpGetCommandProcessor method handleCluster.
private void handleCluster(HttpGetCommand command) {
Node node = textCommandService.getNode();
StringBuilder res = new StringBuilder(node.getClusterService().membersString());
res.append("\n");
ConnectionManager connectionManager = node.getConnectionManager();
res.append("ConnectionCount: ").append(connectionManager.getCurrentClientConnections());
res.append("\n");
res.append("AllConnectionCount: ").append(connectionManager.getAllTextConnections());
res.append("\n");
command.setResponse(null, stringToBytes(res.toString()));
}
use of com.hazelcast.instance.Node in project hazelcast by hazelcast.
the class HttpGetCommandProcessor method handleGetClusterVersion.
private void handleGetClusterVersion(HttpGetCommand command) {
String res = "{\"status\":\"${STATUS}\",\"version\":\"${VERSION}\"}";
Node node = textCommandService.getNode();
ClusterService clusterService = node.getClusterService();
res = res.replace("${STATUS}", "success");
res = res.replace("${VERSION}", clusterService.getClusterVersion().toString());
command.setResponse(HttpCommand.CONTENT_TYPE_JSON, stringToBytes(res));
}
Aggregations