コード例 #1
0
  /** @return Client configuration for the test. */
  protected GridClientConfiguration clientConfiguration() throws GridClientException {
    GridClientConfiguration cfg = new GridClientConfiguration();

    cfg.setBalancer(getBalancer());

    cfg.setTopologyRefreshFrequency(TOP_REFRESH_FREQ);

    cfg.setProtocol(protocol());
    cfg.setServers(Arrays.asList(serverAddress()));
    cfg.setSslContextFactory(sslContextFactory());

    GridClientDataConfiguration loc = new GridClientDataConfiguration();

    GridClientDataConfiguration partitioned = new GridClientDataConfiguration();

    partitioned.setName(PARTITIONED_CACHE_NAME);
    partitioned.setAffinity(new GridClientPartitionAffinity());

    GridClientDataConfiguration replicated = new GridClientDataConfiguration();
    replicated.setName(REPLICATED_CACHE_NAME);

    GridClientDataConfiguration replicatedAsync = new GridClientDataConfiguration();
    replicatedAsync.setName(REPLICATED_ASYNC_CACHE_NAME);

    cfg.setDataConfigurations(Arrays.asList(loc, partitioned, replicated, replicatedAsync));

    return cfg;
  }
コード例 #2
0
  /** @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);
    }
  }
コード例 #3
0
 /**
  * Create a new broker connection with a client-provided name, picking the first available address
  * from the list.
  *
  * <p>If <a href="http://www.rabbitmq.com/api-guide.html#recovery">automatic connection
  * recovery</a> is enabled, the connection returned by this method will be {@link Recoverable}.
  * Future reconnection attempts will pick a random accessible address from the provided list.
  *
  * @param executor thread execution service for consumers on the connection
  * @param addrs an array of known broker addresses (hostname/port pairs) to try in order
  * @param clientProvidedName application-specific connection name, will be displayed in the
  *     management UI if RabbitMQ server supports it. This value doesn't have to be unique and
  *     cannot be used as a connection identifier e.g. in HTTP API requests. This value is supposed
  *     to be human-readable.
  * @return an interface to the connection
  * @throws java.io.IOException if it encounters a problem
  * @see <a href="http://www.rabbitmq.com/api-guide.html#recovery">Automatic Recovery</a>
  */
 public Connection newConnection(
     ExecutorService executor, Address[] addrs, String clientProvidedName)
     throws IOException, TimeoutException {
   return newConnection(executor, Arrays.asList(addrs), clientProvidedName);
 }
コード例 #4
0
 /**
  * Create a new broker connection, picking the first available address from the list.
  *
  * <p>If <a href="http://www.rabbitmq.com/api-guide.html#recovery">automatic connection
  * recovery</a> is enabled, the connection returned by this method will be {@link Recoverable}.
  * Future reconnection attempts will pick a random accessible address from the provided list.
  *
  * @param executor thread execution service for consumers on the connection
  * @param addrs an array of known broker addresses (hostname/port pairs) to try in order
  * @return an interface to the connection
  * @throws java.io.IOException if it encounters a problem
  * @see <a href="http://www.rabbitmq.com/api-guide.html#recovery">Automatic Recovery</a>
  */
 public Connection newConnection(ExecutorService executor, Address[] addrs)
     throws IOException, TimeoutException {
   return newConnection(executor, Arrays.asList(addrs), null);
 }
コード例 #5
0
 /**
  * Create a new broker connection with a client-provided name, picking the first available address
  * from the list.
  *
  * <p>If <a href="http://www.rabbitmq.com/api-guide.html#recovery">automatic connection
  * recovery</a> is enabled, the connection returned by this method will be {@link Recoverable}.
  * Future reconnection attempts will pick a random accessible address from the provided list.
  *
  * @param addrs an array of known broker addresses (hostname/port pairs) to try in order
  * @param clientProvidedName application-specific connection name, will be displayed in the
  *     management UI if RabbitMQ server supports it. This value doesn't have to be unique and
  *     cannot be used as a connection identifier e.g. in HTTP API requests. This value is supposed
  *     to be human-readable.
  * @return an interface to the connection
  * @throws IOException if it encounters a problem
  */
 public Connection newConnection(Address[] addrs, String clientProvidedName)
     throws IOException, TimeoutException {
   return newConnection(this.sharedExecutor, Arrays.asList(addrs), clientProvidedName);
 }
コード例 #6
0
 /**
  * Create a new broker connection, picking the first available address from the list.
  *
  * <p>If <a href="http://www.rabbitmq.com/api-guide.html#recovery">automatic connection
  * recovery</a> is enabled, the connection returned by this method will be {@link Recoverable}.
  * Future reconnection attempts will pick a random accessible address from the provided list.
  *
  * @param addrs an array of known broker addresses (hostname/port pairs) to try in order
  * @return an interface to the connection
  * @throws IOException if it encounters a problem
  */
 public Connection newConnection(Address[] addrs) throws IOException, TimeoutException {
   return newConnection(this.sharedExecutor, Arrays.asList(addrs), null);
 }