/** @throws Exception If failed. */
  public void testClientAffinity() throws Exception {
    GridClientData partitioned = client.data(PARTITIONED_CACHE_NAME);

    Collection<Object> keys = new ArrayList<>();

    keys.addAll(Arrays.asList(Boolean.TRUE, Boolean.FALSE, 1, Integer.MAX_VALUE));

    Random rnd = new Random();
    StringBuilder sb = new StringBuilder();

    // Generate some random strings.
    for (int i = 0; i < 100; i++) {
      sb.setLength(0);

      for (int j = 0; j < 255; j++)
        // Only printable ASCII symbols for test.
        sb.append((char) (rnd.nextInt(0x7f - 0x20) + 0x20));

      keys.add(sb.toString());
    }

    // Generate some more keys to achieve better coverage.
    for (int i = 0; i < 100; i++) keys.add(UUID.randomUUID());

    for (Object key : keys) {
      UUID nodeId = grid(0).mapKeyToNode(PARTITIONED_CACHE_NAME, key).id();

      UUID clientNodeId = partitioned.affinity(key);

      assertEquals(
          "Invalid affinity mapping for REST response for key: " + key, nodeId, clientNodeId);
    }
  }
Ejemplo n.º 2
0
 static String outputOf(Reader r) throws IOException {
   final StringBuilder sb = new StringBuilder();
   final char[] buf = new char[1024];
   int n;
   while ((n = r.read(buf)) > 0) sb.append(buf, 0, n);
   return sb.toString();
 }
Ejemplo n.º 3
0
 static void equalAnyOf(Object x, Object[] y) {
   if (x == null && y == null) {
     pass();
     return;
   }
   for (Object z : y) {
     if (x.equals(z)) {
       pass();
       return;
     }
   }
   StringBuilder sb = new StringBuilder();
   for (Object o : y) sb.append(o).append(" ");
   fail(x + " not equal to one of [" + sb + "]");
 }