Пример #1
0
  @Override
  public void start() throws CacheLoaderException {
    final Marshaller marshaller;
    if (configuration.marshaller() != null) {
      marshaller =
          Util.getInstance(
              configuration.marshaller(), ctx.getCache().getCacheConfiguration().classLoader());
    } else if (configuration.hotRodWrapping()) {
      marshaller = new HotRodEntryMarshaller(ctx.getByteBufferFactory());
    } else if (configuration.rawValues()) {
      marshaller = new GenericJBossMarshaller();
    } else {
      marshaller = ctx.getMarshaller();
    }
    ConfigurationBuilder builder = buildRemoteConfiguration(configuration, marshaller);
    remoteCacheManager = new RemoteCacheManager(builder.build());

    if (configuration.remoteCacheName().equals(BasicCacheContainer.DEFAULT_CACHE_NAME))
      remoteCache = remoteCacheManager.getCache();
    else remoteCache = remoteCacheManager.getCache(configuration.remoteCacheName());
    if (configuration.rawValues() && iceFactory == null) {
      iceFactory =
          ctx.getCache()
              .getAdvancedCache()
              .getComponentRegistry()
              .getComponent(InternalEntryFactory.class);
    }
  }
Пример #2
0
 @Before
 public void initialize() {
   if (remoteCacheManager == null) {
     Configuration config = createRemoteCacheManagerConfiguration();
     remoteCacheManager = new RemoteCacheManager(config, true);
   }
   scriptCache = remoteCacheManager.getCache(SCRIPT_CACHE_NAME);
   remoteCache = remoteCacheManager.getCache();
 }
Пример #3
0
  @Test
  @WithRunningServer({@RunningServer(name = "standalone-customtask")})
  public void shouldThrowExceptionInViaTask() throws Exception {
    RemoteCacheManager rcm = ITestUtils.createCacheManager(server);

    exceptionRule.expect(HotRodClientException.class);
    exceptionRule.expectMessage(LocalExceptionalServerTask.EXCEPTION_MESSAGE);

    rcm.getCache().execute(LocalExceptionalServerTask.NAME, Collections.emptyMap());
  }
 /**
  * Kills a group of remote cache managers.
  *
  * @param rcm the remote cache manager instances to kill
  */
 public static void killRemoteCacheManagers(RemoteCacheManager... rcms) {
   if (rcms != null) {
     for (RemoteCacheManager rcm : rcms) {
       try {
         if (rcm != null) rcm.stop();
       } catch (Throwable t) {
         log.warn("Error stopping remote cache manager", t);
       }
     }
   }
 }
Пример #5
0
  @Test
  @WithRunningServer({@RunningServer(name = "standalone-customtask")})
  public void shouldWorkWithCustomMojo() throws Exception {
    RemoteCacheManager rcm = ITestUtils.createCacheManager(server);
    RemoteCache remoteCache = rcm.getCache();

    Map params = new HashMap();
    params.put("greeting", toBytes(new Greeting("hello, good morning :)")));

    String result = (String) remoteCache.execute(GreetingServerTask.NAME, params);
    assertEquals("hello, good morning :)", result);
  }
Пример #6
0
  @Test
  @WithRunningServer({@RunningServer(name = "standalone-customtask")})
  public void shouldExecuteMapReduceViaJavaScriptInTask() throws Exception {
    RemoteCacheManager rcm = ITestUtils.createCacheManager(server);
    RemoteCache remoteCache = rcm.getCache();
    remoteCache.put(1, "word1 word2 word3");
    remoteCache.put(2, "word1 word2");
    remoteCache.put(3, "word1");

    Map<String, Long> result =
        (Map<String, Long>) remoteCache.execute(JSExecutingServerTask.NAME, Collections.emptyMap());
    assertEquals(3, result.size());
    assertEquals(3, result.get("word1").intValue());
    assertEquals(2, result.get("word2").intValue());
    assertEquals(1, result.get("word3").intValue());
  }
Пример #7
0
  @Test
  @WithRunningServer({@RunningServer(name = "standalone-customtask")})
  public void shouldModifyCacheInViaTask() throws Exception {
    RemoteCacheManager rcm = ITestUtils.createCacheManager(server);

    String value = "value";
    rcm.getCache().put(LocalTestServerTask.TASK_EXECUTED, value);
    rcm.getCache().execute(LocalTestServerTask.NAME, Collections.emptyMap());

    assertEquals(
        LocalTestServerTask.MODIFIED_PREFIX + value,
        rcm.getCache().get(LocalTestServerTask.TASK_EXECUTED));
    assertEquals(
        LocalTestServerTask.MODIFIED_PREFIX + value,
        rcm.getCache(LocalTestServerTask.CACHE_NAME).get(LocalTestServerTask.TASK_EXECUTED));
  }
 @Override
 protected void setup() throws Exception {
   super.setup();
   hotrodServer = createHotRodServer();
   remoteCacheManager = getRemoteCacheManager();
   remoteCacheManager.getCache(); // start the cache
 }
 @Before
 public void initialize() {
   if (remoteCacheManager == null) {
     Configuration config = createRemoteCacheManagerConfiguration();
     remoteCacheManager = new RemoteCacheManager(config, true);
   }
   remoteCache = remoteCacheManager.getCache(TEST_CACHE_NAME);
   assertCacheEmpty();
 }
 protected RemoteCacheManager getCacheManager() {
   if (cacheManager == null) {
     Configuration config =
         new ConfigurationBuilder().addServer().host("localhost").port(11222).build();
     cacheManager = new RemoteCacheManager(config, true);
     cacheManager.start();
   }
   return cacheManager;
 }
 public static void main(String[] args) throws InterruptedException {
   // Create a configuration for a locally-running server
   ConfigurationBuilder builder = new ConfigurationBuilder();
   builder.addServer().host("127.0.0.1").port(ConfigurationProperties.DEFAULT_HOTROD_PORT);
   // Connect to the server
   RemoteCacheManager cacheManager = new RemoteCacheManager(builder.build());
   // Obtain the remote cache
   RemoteCache<String, String> cache = cacheManager.getCache();
   // Register a listener
   MyListener listener = new MyListener();
   cache.addClientListener(listener);
   // Store some values
   cache.put("key1", "value1");
   cache.put("key2", "value2");
   cache.put("key1", "newValue");
   // Remote events are asynchronous, so wait a bit
   Thread.sleep(1000);
   // Remove listener
   cache.removeClientListener(listener);
   // Stop the cache manager and release all resources
   cacheManager.stop();
 }
Пример #12
0
  @Test
  public void testSimpleScriptExecutionWithParams() throws IOException {
    RemoteCache<String, String> remoteCache = remoteCacheManager.getCache(COMPATIBILITY_CACHE_NAME);
    addScripts("test.js");

    Map<String, Object> parameters = new HashMap<>();
    parameters.put("key", "parameter");
    parameters.put("value", "value");

    int result = remoteCache.execute("test.js", parameters);

    assertEquals(1, result);
    assertEquals("value", remoteCache.get("parameter"));
  }
Пример #13
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);
 }
  @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();
  }
Пример #15
0
  @Test
  public void testMapReduceScriptExecution() throws IOException {
    RemoteCache<String, String> remoteCache = remoteCacheManager.getCache(COMPATIBILITY_CACHE_NAME);
    addScripts("stream_serverTask.js");
    remoteCache.put("1", "word1 word2 word3");
    remoteCache.put("2", "word1 word2");
    remoteCache.put("3", "word1");

    Map<String, Long> results = remoteCache.execute("stream_serverTask.js", emptyMap());

    assertEquals(3, results.size());
    assertTrue(results.get("word1").equals(Long.valueOf(3)));
    assertTrue(results.get("word2").equals(Long.valueOf(2)));
    assertTrue(results.get("word3").equals(Long.valueOf(1)));
  }
Пример #16
0
  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);
  }
  @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;
  }
Пример #18
0
  private Object generateKeyAndShutdownServer()
      throws IOException, ClassNotFoundException, InterruptedException {
    resetStats();
    Cache<Object, Object> cache = manager(1).getCache();
    ExecutorService ex = Executors.newSingleThreadExecutor(getTestThreadFactory("KeyGenerator"));
    KeyAffinityService kaf =
        KeyAffinityServiceFactory.newKeyAffinityService(cache, ex, new ByteKeyGenerator(), 2, true);
    Address address = cache.getAdvancedCache().getRpcManager().getTransport().getAddress();
    byte[] keyBytes = (byte[]) kaf.getKeyForAddress(address);
    String key = ByteKeyGenerator.getStringObject(keyBytes);
    ex.shutdownNow();
    kaf.stop();

    remoteCache.put(key, "v");
    assertOnlyServerHit(getAddress(hotRodServer2));
    TcpTransportFactory tcpTp =
        (TcpTransportFactory)
            ((InternalRemoteCacheManager) remoteCacheManager).getTransportFactory();

    Marshaller sm = new JBossMarshaller();
    TcpTransport transport =
        (TcpTransport)
            tcpTp.getTransport(
                sm.objectToByteBuffer(key, 64), null, RemoteCacheManager.cacheNameBytes());
    try {
      assertEquals(
          transport.getServerAddress(),
          new InetSocketAddress("localhost", hotRodServer2.getPort()));
    } finally {
      tcpTp.releaseTransport(transport);
    }

    log.info("About to stop Hot Rod server 2");
    hotRodServer2.stop();

    return key;
  }
  @Test
  public void testHotRodRollingUpgradesDiffVersions() throws Exception {
    // Target node
    final int managementPortServer1 = 9990;
    MBeanServerConnectionProvider provider1;
    // Source node
    int managementPortServer2 = 10099; // jboss-as mgmt port
    MBeanServerConnectionProvider provider2;

    try {

      if (!Boolean.parseBoolean(System.getProperty("start.jboss.as.manually"))) {
        // start it by Arquillian
        controller.start("hotrod-rolling-upgrade-2-old");
        managementPortServer2 = 10090;
      }

      ConfigurationBuilder builder = new ConfigurationBuilder();
      builder
          .addServer()
          .host("127.0.0.1")
          .port(11322)
          .protocolVersion(ConfigurationProperties.PROTOCOL_VERSION_12);

      RemoteCacheManager rcm = new RemoteCacheManager(builder.build());
      final RemoteCache<String, String> c2 = rcm.getCache("default");

      c2.put("key1", "value1");
      assertEquals("value1", c2.get("key1"));

      for (int i = 0; i < 50; i++) {
        c2.put("keyLoad" + i, "valueLoad" + i);
      }

      controller.start("hotrod-rolling-upgrade-1");

      RemoteInfinispanMBeans s1 =
          createRemotes("hotrod-rolling-upgrade-1", "local", DEFAULT_CACHE_NAME);
      // hotrod.protocol.version, if explictily defined, is set in createRemotes() method
      final RemoteCache<Object, Object> c1 = createCache(s1);

      assertEquals(
          "Can't access etries stored in source node (target's RemoteCacheStore).",
          "value1",
          c1.get("key1"));

      provider2 = new MBeanServerConnectionProvider("127.0.0.1", managementPortServer2);

      final ObjectName rollMan =
          new ObjectName(
              "jboss."
                  + InfinispanSubsystem.SUBSYSTEM_NAME
                  + ":type=Cache,"
                  + "name=\"default(local)\","
                  + "manager=\"local\","
                  + "component=RollingUpgradeManager");

      invokeOperation(
          provider2,
          rollMan.toString(),
          "recordKnownGlobalKeyset",
          new Object[] {},
          new String[] {});

      provider1 =
          new MBeanServerConnectionProvider(
              s1.server.getHotrodEndpoint().getInetAddress().getHostName(), managementPortServer1);

      invokeOperation(
          provider1,
          rollMan.toString(),
          "synchronizeData",
          new Object[] {"hotrod"},
          new String[] {"java.lang.String"});

      invokeOperation(
          provider1,
          rollMan.toString(),
          "disconnectSource",
          new Object[] {"hotrod"},
          new String[] {"java.lang.String"});

      // is source (RemoteCacheStore) really disconnected?
      c2.put("disconnected", "source");
      assertEquals(
          "Can't obtain value from cache2 (source node).", "source", c2.get("disconnected"));
      assertNull(
          "Source node entries should NOT be accessible from target node (after RCS disconnection)",
          c1.get("disconnected"));

      // all entries migrated?
      assertEquals("Entry was not successfully migrated.", "value1", c1.get("key1"));
      for (int i = 0; i < 50; i++) {
        assertEquals(
            "Entry was not successfully migrated.", "valueLoad" + i, c1.get("keyLoad" + i));
      }
    } finally {
      if (controller.isStarted("hotrod-rolling-upgrade-1")) {
        controller.stop("hotrod-rolling-upgrade-1");
      }
      if (controller.isStarted("hotrod-rolling-upgrade-2-old")) {
        controller.stop("hotrod-rolling-upgrade-2-old");
      }
    }
  }
 protected void initialize(Subject subj) throws PrivilegedActionException {
   final Configuration config = getRemoteCacheManagerConfig(subj);
   remoteCacheManager = new RemoteCacheManager(config, true);
   remoteCache = remoteCacheManager.getCache(TEST_CACHE_NAME);
 }
 public void stop() {
   if (cacheManager != null) {
     cacheManager.stop();
   }
 }
 protected void initializeOverSsl(String login, String password) {
   Configuration config = getRemoteCacheManagerOverSslConfig(login, password);
   remoteCacheManager = new RemoteCacheManager(config, true);
   remoteCache = remoteCacheManager.getCache(TEST_CACHE_NAME);
 }
Пример #23
0
 @AfterClass
 public static void release() {
   if (remoteCacheManager != null) {
     remoteCacheManager.stop();
   }
 }
Пример #24
0
 @Override
 public void stop() throws CacheLoaderException {
   remoteCacheManager.stop();
 }
Пример #25
0
 @After
 public void clearCache() {
   remoteCache.clear();
   remoteCacheManager.getCache(COMPATIBILITY_CACHE_NAME).clear();
 }