コード例 #1
0
  @Test
  public void testGetPartition() {
    String key = "Key";

    PartitionService clientPartitionService = client.getPartitionService();
    Partition clientPartition = clientPartitionService.getPartition(key);

    PartitionService serverPartitionService = server.getPartitionService();
    Partition serverPartition = serverPartitionService.getPartition(key);

    assertEquals(clientPartition.getPartitionId(), serverPartition.getPartitionId());
  }
コード例 #2
0
 /**
  * Returns the next {@code long} key owned by the given Hazelcast instance.
  *
  * @param instance Hazelcast instance to search next key for
  * @param lastKey last key to start search from
  * @return next key owned by given Hazelcast instance
  */
 public static long nextKeyOwnedBy(HazelcastInstance instance, long lastKey) {
   Member localMember = instance.getCluster().getLocalMember();
   PartitionService partitionService = instance.getPartitionService();
   while (true) {
     Partition partition = partitionService.getPartition(lastKey);
     if (localMember.equals(partition.getOwner())) {
       return lastKey;
     }
     lastKey++;
   }
 }
コード例 #3
0
 public static String generateKeyNotOwnedBy(HazelcastInstance instance) {
   final Member localMember = instance.getCluster().getLocalMember();
   final PartitionService partitionService = instance.getPartitionService();
   for (; ; ) {
     String id = UUID.randomUUID().toString();
     Partition partition = partitionService.getPartition(id);
     if (!localMember.equals(partition.getOwner())) {
       return id;
     }
   }
 }
コード例 #4
0
  private HazelcastInstance getOwnerNode(String key, HazelcastInstance[] nodes) {
    PartitionService partitionService = nodes[0].getPartitionService();
    Partition partition = partitionService.getPartition(key);
    Member owner = partition.getOwner();

    for (int i = 0; i < nodes.length; i++) {
      HazelcastInstance node = nodes[i];
      Member localMember = node.getCluster().getLocalMember();
      if (localMember.equals(owner)) {
        return node;
      }
    }

    throw new IllegalStateException("This should not be happen...");
  }
コード例 #5
0
  @Setup
  public void setup(TestContext testContext) throws Exception {
    this.testContext = testContext;
    targetInstance = testContext.getTargetInstance();
    testId = testContext.getTestId();

    integrityMap = targetInstance.getMap(basename + "Integrity");
    stressMap = targetInstance.getMap(basename + "Stress");

    integrityThreads = new MapIntegrityThread[mapIntegrityThreadCount];
    value = new byte[valueSize];

    Random random = new Random();
    random.nextBytes(value);

    if (mapLoad && isMemberNode(targetInstance)) {
      PartitionService partitionService = targetInstance.getPartitionService();
      final Set<Partition> partitionSet = partitionService.getPartitions();
      for (Partition partition : partitionSet) {
        while (partition.getOwner() == null) {
          Thread.sleep(1000);
        }
      }
      LOGGER.info(testId + ": " + partitionSet.size() + " partitions");

      Member localMember = targetInstance.getCluster().getLocalMember();
      for (int i = 0; i < totalIntegrityKeys; i++) {
        Partition partition = partitionService.getPartition(i);
        if (localMember.equals(partition.getOwner())) {
          integrityMap.put(i, value);
        }
      }
      LOGGER.info(
          testId + ": integrityMap=" + integrityMap.getName() + " size=" + integrityMap.size());

      Config config = targetInstance.getConfig();
      MapConfig mapConfig = config.getMapConfig(integrityMap.getName());
      LOGGER.info(testId + ": " + mapConfig);
    }
  }