Search in sources :

Example 66 with Node

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));
}
Also used : EvictionPolicyEvaluator(com.hazelcast.internal.eviction.impl.evaluator.EvictionPolicyEvaluator) Node(com.hazelcast.instance.Node) SerializationService(com.hazelcast.spi.serialization.SerializationService) Data(com.hazelcast.nio.serialization.Data) CacheObjectRecord(com.hazelcast.cache.impl.record.CacheObjectRecord) CacheContext(com.hazelcast.cache.impl.CacheContext) CacheRecordHashMap(com.hazelcast.cache.impl.record.CacheRecordHashMap) EVICT_ALWAYS(com.hazelcast.internal.eviction.EvictionChecker.EVICT_ALWAYS) ICacheService(com.hazelcast.cache.impl.ICacheService) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 67 with Node

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();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Node(com.hazelcast.instance.Node) Before(org.junit.Before)

Example 68 with Node

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()));
}
Also used : ClusterState(com.hazelcast.cluster.ClusterState) NodeState(com.hazelcast.instance.NodeState) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) Node(com.hazelcast.instance.Node) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl)

Example 69 with Node

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()));
}
Also used : ConnectionManager(com.hazelcast.nio.ConnectionManager) Node(com.hazelcast.instance.Node)

Example 70 with Node

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));
}
Also used : ClusterService(com.hazelcast.internal.cluster.ClusterService) Node(com.hazelcast.instance.Node)

Aggregations

Node (com.hazelcast.instance.Node)131 HazelcastInstance (com.hazelcast.core.HazelcastInstance)60 Test (org.junit.Test)50 QuickTest (com.hazelcast.test.annotation.QuickTest)45 ParallelTest (com.hazelcast.test.annotation.ParallelTest)42 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)21 ClientEventRegistration (com.hazelcast.client.spi.impl.listener.ClientEventRegistration)18 Address (com.hazelcast.nio.Address)17 Config (com.hazelcast.config.Config)14 ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)13 ILogger (com.hazelcast.logging.ILogger)10 Data (com.hazelcast.nio.serialization.Data)10 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)10 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)9 StringUtil.bytesToString (com.hazelcast.util.StringUtil.bytesToString)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 ClusterService (com.hazelcast.internal.cluster.ClusterService)7 SerializationService (com.hazelcast.spi.serialization.SerializationService)7 ItemListener (com.hazelcast.core.ItemListener)6 Operation (com.hazelcast.spi.Operation)6