Пример #1
0
 public static void warmUpPartitions(HazelcastInstance... instances) throws InterruptedException {
   for (HazelcastInstance instance : instances) {
     final PartitionService ps = instance.getPartitionService();
     for (Partition partition : ps.getPartitions()) {
       while (partition.getOwner() == null) {
         Thread.sleep(10);
       }
     }
   }
 }
 private static void warmUpPartitions(HazelcastInstance... instances) {
   for (HazelcastInstance instance : instances) {
     PartitionService partitionService = instance.getPartitionService();
     for (Partition partition : partitionService.getPartitions()) {
       while (partition.getOwner() == null) {
         sleepSeconds(1);
       }
     }
   }
 }
Пример #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;
     }
   }
 }
 /**
  * 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++;
   }
 }
  @Test
  public void testGetPartitions() {
    String key = "Key";

    PartitionService clientPartitionService = client.getPartitionService();
    Set<Partition> clientPartitions = clientPartitionService.getPartitions();

    PartitionService serverPartitionService = server.getPartitionService();
    Set<Partition> serverPartitions = serverPartitionService.getPartitions();

    assertEquals(clientPartitions.size(), serverPartitions.size());
  }
  @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());
  }
  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...");
  }
  @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);
    }
  }
 @Test
 public void testRandomPartitionKeyNotNull() {
   PartitionService p = client.getPartitionService();
   String key = p.randomPartitionKey();
   assertNotNull(key);
 }
 @Test(expected = UnsupportedOperationException.class)
 public void testRemoveMigrationListener() throws Exception {
   PartitionService p = client.getPartitionService();
   p.removeMigrationListener("");
 }
 @Test(expected = UnsupportedOperationException.class)
 public void testAddMigrationListener() throws Exception {
   PartitionService p = client.getPartitionService();
   p.addMigrationListener(new DumMigrationListener());
 }