public static byte[] getKeyForServer(HotRodServer primaryOwner, String cacheName) {
    GenericJBossMarshaller marshaller = new GenericJBossMarshaller();
    Cache<?, ?> cache =
        cacheName != null
            ? primaryOwner.getCacheManager().getCache(cacheName)
            : primaryOwner.getCacheManager().getCache();
    Random r = new Random();
    byte[] dummy = new byte[8];
    int attemptsLeft = 1000;
    try {
      do {
        r.nextBytes(dummy);
        attemptsLeft--;
      } while (!isFirstOwner(cache, marshaller.objectToByteBuffer(dummy)) && attemptsLeft >= 0);
    } catch (IOException e) {
      throw new AssertionError(e);
    } catch (InterruptedException e) {
      throw new AssertionError(e);
    }

    if (attemptsLeft < 0)
      throw new IllegalStateException("Could not find any key owned by " + primaryOwner);

    log.infof(
        "Binary key %s hashes to [cluster=%s,hotrod=%s]",
        Util.printArray(dummy, false),
        primaryOwner.getCacheManager().getAddress(),
        primaryOwner.getAddress());

    return dummy;
  }
  public void testHotRodEncoding() throws Exception {
    Cache<byte[], byte[]> cache = cacheManager.getCache();
    RemoteCache<String, String> remoteCache = remoteCacheManager.getCache();
    remoteCache.put("k1", "v1");
    GenericJBossMarshaller marshaller = new GenericJBossMarshaller();
    byte[] k1 = marshaller.objectToByteBuffer("k1");
    assertTrue(cache.containsKey(k1));

    String sessionId = interpreter.createSessionId(BasicCacheContainer.DEFAULT_CACHE_NAME);
    interpreter.execute(sessionId, "encoding hotrod;");
    Map<String, String> response = interpreter.execute(sessionId, "get k1;");
    assertEquals("v1", response.get(ResultKeys.OUTPUT.toString()));

    assertInterpreter(interpreter.execute(sessionId, "put k2 v2;"));
    String v2 = remoteCache.get("k2");
    assertEquals("v2", v2);
  }