Пример #1
0
 @Test
 public void testTTL() throws Exception {
   Config config = new Config();
   FactoryImpl mockFactory = mock(FactoryImpl.class);
   // we mocked the node
   // do not forget to shutdown the connectionManager
   // so that server socket can be released.
   Node node = new Node(mockFactory, config);
   node.serviceThread = Thread.currentThread();
   CMap cmap = new CMap(node.concurrentMapManager, "c:myMap");
   Object key = "1";
   Object value = "istanbul";
   Data dKey = toData(key);
   Data dValue = toData(value);
   Request reqPut = newPutRequest(dKey, dValue);
   reqPut.ttl = 3000;
   cmap.put(reqPut);
   assertTrue(cmap.mapRecords.containsKey(toData(key)));
   Data actualValue = cmap.get(newGetRequest(dKey));
   assertThat(toObject(actualValue), equalTo(value));
   assertEquals(1, cmap.mapRecords.size());
   Record record = cmap.getRecord(dKey);
   assertNotNull(record);
   assertTrue(record.isActive());
   assertTrue(record.isValid());
   assertEquals(1, cmap.size());
   assertNotNull(cmap.get(newGetRequest(dKey)));
   assertEquals(dValue, cmap.get(newGetRequest(dKey)));
   assertTrue(record.getRemainingTTL() > 1000);
   Thread.sleep(1000);
   assertTrue(record.getRemainingTTL() < 2100);
   cmap.put(newPutRequest(dKey, dValue));
   assertTrue(record.getRemainingTTL() > 2001);
   assertTrue(record.isActive());
   assertTrue(record.isValid());
   Thread.sleep(1000);
   assertTrue(record.getRemainingTTL() < 2100);
   cmap.put(newPutRequest(dKey, dValue));
   assertTrue(record.getRemainingTTL() > 2001);
   assertTrue(record.isActive());
   assertTrue(record.isValid());
   Thread.sleep(5000);
   assertEquals(0, cmap.size());
   assertTrue(cmap.evict(newEvictRequest(dKey)));
   assertTrue(cmap.shouldPurgeRecord(record, System.currentTimeMillis() + 10000));
   cmap.removeAndPurgeRecord(record);
   assertEquals(0, cmap.mapRecords.size());
   assertEquals(0, cmap.size());
   assertEquals(0, cmap.mapIndexService.size());
   node.connectionManager.shutdown();
 }
 private void createMemberState(MemberStateImpl memberState) {
   final Node node = factory.node;
   memberState.setAddress(node.getThisAddress());
   memberState.getMemberHealthStats().setOutOfMemory(node.isOutOfMemory());
   memberState.getMemberHealthStats().setActive(node.isActive());
   memberState
       .getMemberHealthStats()
       .setServiceThreadStats(node.getCpuUtilization().serviceThread);
   memberState.getMemberHealthStats().setOutThreadStats(node.getCpuUtilization().outThread);
   memberState.getMemberHealthStats().setInThreadStats(node.getCpuUtilization().inThread);
   PartitionService partitionService = factory.getPartitionService();
   Set<Partition> partitions = partitionService.getPartitions();
   memberState.clearPartitions();
   for (Partition partition : partitions) {
     if (partition.getOwner() != null && partition.getOwner().localMember()) {
       memberState.addPartition(partition.getPartitionId());
     }
   }
   Collection<HazelcastInstanceAwareInstance> proxyObjects =
       new ArrayList<HazelcastInstanceAwareInstance>(factory.getProxies());
   createMemState(memberState, proxyObjects.iterator(), InstanceType.MAP);
   createMemState(memberState, proxyObjects.iterator(), InstanceType.QUEUE);
   createMemState(memberState, proxyObjects.iterator(), InstanceType.TOPIC);
   createRuntimeProps(memberState);
   // uncomment when client changes are made
   // createMemState(memberState, proxyObjects.iterator(), InstanceType.ATOMIC_LONG);
   // createMemState(memberState, proxyObjects.iterator(), InstanceType.COUNT_DOWN_LATCH);
   // createMemState(memberState, proxyObjects.iterator(), InstanceType.SEMAPHORE);
 }
Пример #3
0
 @Test
 public void testPut() throws Exception {
   Config config = new Config();
   FactoryImpl mockFactory = mock(FactoryImpl.class);
   // we mocked the node
   // do not forget to shutdown the connectionManager
   // so that server socket can be released.
   Node node = new Node(mockFactory, config);
   node.serviceThread = Thread.currentThread();
   CMap cmap = new CMap(node.concurrentMapManager, "c:myMap");
   Object key = "1";
   Object value = "istanbul";
   Data dKey = toData(key);
   Data dValue = toData(value);
   cmap.put(newPutRequest(dKey, dValue));
   assertTrue(cmap.mapRecords.containsKey(toData(key)));
   Data actualValue = cmap.get(newGetRequest(dKey));
   assertThat(toObject(actualValue), equalTo(value));
   assertEquals(1, cmap.mapRecords.size());
   Record record = cmap.getRecord(dKey);
   assertNotNull(record);
   assertTrue(record.isActive());
   assertTrue(record.isValid());
   assertEquals(1, cmap.size());
   cmap.remove(newRemoveRequest(dKey));
   assertTrue(System.currentTimeMillis() - record.getRemoveTime() < 100);
   assertEquals(1, cmap.mapRecords.size());
   record = cmap.getRecord(dKey);
   assertNotNull(record);
   assertFalse(record.isActive());
   assertFalse(record.isValid());
   assertEquals(0, cmap.size());
   cmap.put(newPutRequest(dKey, dValue, 1000));
   assertEquals(0, record.getRemoveTime());
   assertTrue(cmap.mapRecords.containsKey(toData(key)));
   Thread.sleep(1500);
   assertEquals(0, cmap.size());
   assertFalse(cmap.containsKey(newContainsRequest(dKey, null)));
   node.connectionManager.shutdown();
 }
Пример #4
0
 @Test
 @Ignore
 public void testCallState() throws Exception {
   Config config = new Config();
   final HazelcastInstance h1 = Hazelcast.newHazelcastInstance(config);
   final HazelcastInstance h2 = Hazelcast.newHazelcastInstance(config);
   final Node node1 = getNode(h1);
   final Node node2 = getNode(h2);
   Thread.sleep(100);
   final CountDownLatch latch = new CountDownLatch(1);
   final IMap imap1 = h1.getMap("default");
   new Thread(
           new Runnable() {
             public void run() {
               imap1.lock("1");
               latch.countDown();
             }
           })
       .start();
   latch.await();
   //        final IMap imap2 = h2.getMap("default");
   final AtomicInteger threadId = new AtomicInteger();
   new Thread(
           new Runnable() {
             public void run() {
               ThreadContext.get().setCurrentFactory(node1.factory);
               threadId.set(ThreadContext.get().getThreadId());
               imap1.put("1", "value1");
             }
           })
       .start();
   Thread.sleep(1000);
   System.out.println(node1.getThisAddress() + " thread " + threadId.get());
   CallState callState1 =
       node1.getSystemLogService().getCallState(node1.getThisAddress(), threadId.get());
   if (callState1 != null) {
     for (Object callStateLog : callState1.getLogs()) {
       System.out.println(callStateLog);
     }
   }
   CallState callState2 =
       node2.getSystemLogService().getCallState(node1.getThisAddress(), threadId.get());
   System.out.println("========================");
   if (callState2 != null) {
     for (Object callStateLog : callState2.getLogs()) {
       System.out.println(callStateLog);
     }
   }
 }