Пример #1
0
 @Override
 protected void setup() throws Exception {
   super.setup();
   hotrodServer = HotRodClientTestingUtil.startHotRodServer(cacheManager);
   port = hotrodServer.getPort();
   remoteCacheManager =
       new RemoteCacheManager(
           new org.infinispan.client.hotrod.configuration.ConfigurationBuilder()
               .addServers("localhost:" + hotrodServer.getPort())
               .build());
   remoteCacheManager.start();
   GlobalComponentRegistry gcr = TestingUtil.extractGlobalComponentRegistry(cacheManager);
   interpreter = gcr.getComponent(Interpreter.class);
 }
 public static String getServersString(HotRodServer... servers) {
   StringBuilder builder = new StringBuilder();
   for (HotRodServer server : servers) {
     builder.append("localhost").append(':').append(server.getPort()).append(";");
   }
   return builder.toString();
 }
 private HotRodServer addHotRodServer() {
   EmbeddedCacheManager cm = addClusterEnabledCacheManager(defaultBuilder);
   cm.defineConfiguration(DIST_ONE_CACHE_NAME, distOneBuilder.build());
   cm.defineConfiguration(DIST_TWO_CACHE_NAME, distTwoBuilder.build());
   HotRodServer server = HotRodClientTestingUtil.startHotRodServer(cm);
   addr2hrServer.put(new InetSocketAddress(server.getHost(), server.getPort()), server);
   return server;
 }
 public void testTouchServer() {
   RemoteCacheManager remoteCacheManager =
       new RemoteCacheManager("localhost", hotRodServer1.getPort(), true);
   RemoteCache<Object, Object> remoteCache = remoteCacheManager.getCache();
   remoteCache.put("k", "v");
   assertEquals("v", remoteCache.get("k"));
   killRemoteCacheManager(remoteCacheManager);
 }
 private void assertRequestRouting(byte[] key, String cacheName, HotRodServer server) {
   RemoteCache<Object, Object> rcOne = rcm.getCache(cacheName);
   InetSocketAddress serverAddress = new InetSocketAddress(server.getHost(), server.getPort());
   for (int i = 0; i < 2; i++) {
     log.infof("Routing put test for key %s", Util.printArray(key, false));
     rcOne.put(key, "value");
     assertServerHit(serverAddress, cacheName, i + 1);
   }
 }
  @Test(dependsOnMethods = "testRoundRobinLoadBalancing")
  public void testAddNewHotrodServer() {
    c4 = TestCacheManagerFactory.createLocalCacheManager(false).getCache();
    hotRodServer4 = TestHelper.startHotRodServer((EmbeddedCacheManager) c4.getCacheManager());
    registerCacheManager(c4.getCacheManager());

    List<SocketAddress> serverAddresses = new ArrayList<SocketAddress>();
    serverAddresses.add(new InetSocketAddress("localhost", hotRodServer1.getPort()));
    serverAddresses.add(new InetSocketAddress("localhost", hotRodServer2.getPort()));
    serverAddresses.add(new InetSocketAddress("localhost", hotRodServer3.getPort()));
    serverAddresses.add(new InetSocketAddress("localhost", hotRodServer4.getPort()));

    RoundRobinBalancingStrategy balancer = getBalancer();
    balancer.setServers(serverAddresses);

    remoteCache.put("k1", "v1");
    remoteCache.put("k2", "v2");
    remoteCache.put("k3", "v3");
    remoteCache.put("k4", "v4");

    assertEquals(1, c1.size());
    assertEquals(1, c2.size());
    assertEquals(1, c3.size());
    assertEquals(1, c4.size());

    assertEquals("v1", remoteCache.get("k1"));
    assertEquals("v2", remoteCache.get("k2"));
    assertEquals("v3", remoteCache.get("k3"));
    assertEquals("v4", remoteCache.get("k4"));

    remoteCache.put("k5", "v2");
    remoteCache.put("k6", "v3");
    remoteCache.put("k7", "v1");
    remoteCache.put("k8", "v2");
    remoteCache.put("k9", "v3");
    remoteCache.put("k10", "v3");
    remoteCache.put("k11", "v3");
    remoteCache.put("k12", "v3");

    assertEquals(3, c1.size());
    assertEquals(3, c2.size());
    assertEquals(3, c3.size());
    assertEquals(3, c4.size());
  }
  @Override
  protected void createCacheManagers() throws Throwable {
    c1 = TestCacheManagerFactory.createLocalCacheManager(false).getCache();
    c2 = TestCacheManagerFactory.createLocalCacheManager(false).getCache();
    c3 = TestCacheManagerFactory.createLocalCacheManager(false).getCache();
    registerCacheManager(c1.getCacheManager(), c2.getCacheManager(), c3.getCacheManager());

    hotRodServer1 = TestHelper.startHotRodServer(c1.getCacheManager());
    hotRodServer2 = TestHelper.startHotRodServer(c2.getCacheManager());
    hotRodServer3 = TestHelper.startHotRodServer(c3.getCacheManager());

    log.trace("Server 1 port: " + hotRodServer1.getPort());
    log.trace("Server 2 port: " + hotRodServer2.getPort());
    log.trace("Server 3 port: " + hotRodServer3.getPort());
    String servers = TestHelper.getServersString(hotRodServer1, hotRodServer2, hotRodServer3);
    log.trace("Server list is: " + servers);
    RemoteCacheManager remoteCacheManager = new RemoteCacheManager(servers);
    remoteCache = remoteCacheManager.getCache();
  }
 protected RemoteCacheManager getRemoteCacheManager() {
   Properties config = new Properties();
   config.put("infinispan.client.hotrod.server_list", "127.0.0.1:" + hotrodServer.getPort());
   config.put("infinispan.client.hotrod.socket_timeout", "5000");
   config.put("infinispan.client.hotrod.connect_timeout", "5000");
   config.put("maxActive", 2);
   // Set ping on startup false, so that the hang can happen
   // when the put comes, and not when the remote cache manager is built.
   config.put("infinispan.client.hotrod.ping_on_startup", "false");
   return new RemoteCacheManager(config);
 }
  @Override
  protected CacheStoreConfig createCacheStoreConfig() throws Exception {
    RemoteCacheStoreConfig remoteCacheStoreConfig = new RemoteCacheStoreConfig();
    localCacheManager = TestCacheManagerFactory.createLocalCacheManager(false);
    hrServer = TestHelper.startHotRodServer(localCacheManager);

    remoteCacheStoreConfig.setRemoteCacheName(CacheContainer.DEFAULT_CACHE_NAME);
    Properties properties = new Properties();
    properties.put("infinispan.client.hotrod.server_list", "localhost:" + hrServer.getPort());
    remoteCacheStoreConfig.setHotRodClientProperties(properties);

    return remoteCacheStoreConfig;
  }
  @Test(dependsOnMethods = "testStopServer")
  public void testRemoveServers() {
    List<SocketAddress> serverAddresses = new ArrayList<SocketAddress>();
    serverAddresses.add(new InetSocketAddress("localhost", hotRodServer1.getPort()));
    serverAddresses.add(new InetSocketAddress("localhost", hotRodServer2.getPort()));

    RoundRobinBalancingStrategy balancer = getBalancer();
    balancer.setServers(serverAddresses);

    remoteCache.put("k1", "v1");
    remoteCache.put("k2", "v2");
    remoteCache.put("k3", "v3");
    remoteCache.put("k4", "v4");

    assertEquals(2, c1.size());
    assertEquals(2, c2.size());
    assertEquals(0, c3.size());
    assertEquals(0, c4.size());

    assertEquals("v1", remoteCache.get("k1"));
    assertEquals("v2", remoteCache.get("k2"));
    assertEquals("v3", remoteCache.get("k3"));
    assertEquals("v4", remoteCache.get("k4"));

    remoteCache.put("k5", "v2");
    remoteCache.put("k6", "v3");
    remoteCache.put("k7", "v1");
    remoteCache.put("k8", "v2");
    remoteCache.put("k9", "v3");
    remoteCache.put("k10", "v3");
    remoteCache.put("k11", "v3");
    remoteCache.put("k12", "v3");

    assertEquals(6, c1.size());
    assertEquals(6, c2.size());
    assertEquals(0, c3.size());
    assertEquals(0, c4.size());
  }
 public static void findServerAndKill(
     RemoteCacheManager client,
     Collection<HotRodServer> servers,
     Collection<EmbeddedCacheManager> cacheManagers) {
   InetSocketAddress addr = (InetSocketAddress) getLoadBalancer(client).nextServer(null);
   for (HotRodServer server : servers) {
     if (server.getPort() == addr.getPort()) {
       HotRodClientTestingUtil.killServers(server);
       TestingUtil.killCacheManagers(server.getCacheManager());
       cacheManagers.remove(server.getCacheManager());
       TestingUtil.blockUntilViewsReceived(50000, false, cacheManagers);
     }
   }
 }
Пример #12
0
  @Override
  protected void createCacheManagers() throws Throwable {
    defaultBuilder = defaultCacheConfigurationBuilder();
    distOneBuilder = hotRodCacheConfiguration(getDefaultClusteredCacheConfig(CacheMode.DIST_SYNC));
    distOneBuilder
        .clustering()
        .hash()
        .numOwners(1)
        .numSegments(1)
        .consistentHashFactory(new ControlledConsistentHashFactory(0));
    distTwoBuilder = hotRodCacheConfiguration(getDefaultClusteredCacheConfig(CacheMode.DIST_SYNC));
    distTwoBuilder
        .clustering()
        .hash()
        .numOwners(1)
        .numSegments(1)
        .consistentHashFactory(new ControlledConsistentHashFactory(1));

    server1 = addHotRodServer();
    server2 = addHotRodServer();

    blockUntilViewReceived(manager(0).getCache(), 2);
    blockUntilCacheStatusAchieved(manager(0).getCache(), ComponentStatus.RUNNING, 10000);
    blockUntilCacheStatusAchieved(manager(1).getCache(), ComponentStatus.RUNNING, 10000);

    org.infinispan.client.hotrod.configuration.ConfigurationBuilder clientBuilder =
        new org.infinispan.client.hotrod.configuration.ConfigurationBuilder();
    clientBuilder
        .addServer()
        .host(server1.getHost())
        .port(server1.getPort())
        .addServer()
        .host(server2.getHost())
        .port(server2.getPort());
    rcm = new RemoteCacheManager(clientBuilder.build());
  }
  @BeforeClass
  public void setup() throws Exception {
    ConfigurationBuilder serverBuilder = TestCacheManagerFactory.getDefaultCacheConfiguration(true);
    serverBuilder
        .eviction()
        .maxEntries(100)
        .strategy(EvictionStrategy.UNORDERED)
        .expiration()
        .wakeUpInterval(10L);
    serverCacheManager = TestCacheManagerFactory.createCacheManager(serverBuilder);
    serverCache = serverCacheManager.getCache();
    sourceServer = TestHelper.startHotRodServer(serverCacheManager);

    remoteSourceCacheManager = new RemoteCacheManager("localhost", sourceServer.getPort());
    remoteSourceCacheManager.start();
    remoteSourceCache = remoteSourceCacheManager.getCache();

    ConfigurationBuilder clientBuilder =
        TestCacheManagerFactory.getDefaultCacheConfiguration(false);
    clientBuilder
        .loaders()
        .addStore(RemoteCacheStoreConfigurationBuilder.class)
        .hotRodWrapping(true)
        .addServer()
        .host("localhost")
        .port(sourceServer.getPort());
    targetCacheManager = TestCacheManagerFactory.createCacheManager(clientBuilder);
    targetCache = targetCacheManager.getCache();
    targetServer = TestHelper.startHotRodServer(targetCacheManager);

    remoteTargetCacheManager = new RemoteCacheManager("localhost", targetServer.getPort());
    remoteTargetCacheManager.start();
    remoteTargetCache = remoteTargetCacheManager.getCache();

    marshaller = remoteTargetCacheManager.getMarshaller();
  }
  @Override
  protected EmbeddedCacheManager createCacheManager() throws Exception {
    latch = new CountDownLatch(1);
    cacheManager =
        new HangingCacheManager(
            TestCacheManagerFactory.createCacheManager(hotRodCacheConfiguration()), latch);
    // cacheManager = TestCacheManagerFactory.createLocalCacheManager();
    // pass the config file to the cache
    hotrodServer = TestHelper.startHotRodServer(cacheManager);
    log.info("Started server on port: " + hotrodServer.getPort());

    remoteCacheManager = getRemoteCacheManager();
    defaultRemote = remoteCacheManager.getCache();

    return cacheManager;
  }
  @Override
  protected EmbeddedCacheManager createCacheManager() throws Exception {
    cacheManager = TestCacheManagerFactory.createCacheManager(hotRodCacheConfiguration());
    cache = cacheManager.getCache();

    hotRodServer = HotRodClientTestingUtil.startHotRodServer(cacheManager);

    ConfigurationBuilder clientBuilder = new ConfigurationBuilder();
    clientBuilder.addServer().host("127.0.0.1").port(hotRodServer.getPort());
    clientBuilder.marshaller(new ProtoStreamMarshaller());
    remoteCacheManager = new RemoteCacheManager(clientBuilder.build());

    remoteCache = remoteCacheManager.getCache();

    // initialize client-side serialization context
    MarshallerRegistration.registerMarshallers(
        ProtoStreamMarshaller.getSerializationContext(remoteCacheManager));

    return cacheManager;
  }
 protected RemoteCacheManager getRemoteCacheManager() {
   ConfigurationBuilder builder = new ConfigurationBuilder();
   builder.addServer().host("127.0.0.1").port(hotrodServer.getPort());
   return new RemoteCacheManager(builder.build());
 }
 public static RemoteCacheManager getRemoteCacheManager(HotRodServer server) {
   ConfigurationBuilder builder = new ConfigurationBuilder();
   builder.addServer().host(server.getHost()).port(server.getPort());
   return new InternalRemoteCacheManager(builder.build());
 }