@Override public <T> T execute(String scriptName, Map<String, ?> params) { return delegate.execute(scriptName, params); }
@Override public <T> T execute(String scriptName, Map<String, ?> params) { return scriptManager.getCache().execute(scriptName, params); }
@Test @SuppressWarnings("unchecked") public void shouldGatherNodeNamesInRemoteTasks() throws Exception { Object resultObject = managers.get(0).getCache().execute(DistributedTestServerTask.NAME, Collections.emptyMap()); assertNotNull(resultObject); List<String> result = (List<String>) resultObject; assertEquals(2, result.size()); System.out.println("The RESULT IS: " + result); assertTrue("result list does not contain expected items.", result.containsAll(expectedServerList)); }
@Test @SuppressWarnings("unchecked") public void shouldThrowExceptionInRemoteTasks() throws Exception { Map<String, Boolean> params = new HashMap<String, Boolean>(); params.put("throwException", true); exceptionRule.expect(HotRodClientException.class); exceptionRule.expectMessage("Intentionally Thrown Exception"); managers.get(0).getCache().execute(DistributedTestServerTask.NAME, params); }
@Test public void testRemovingNonExistentScript() { exceptionRule.expect(HotRodClientException.class); exceptionRule.expectMessage("Unknown task"); remoteCache.execute("nonExistent.js", new HashMap<>()); }
@Test public void testScriptExecution() throws Exception { remoteCache.clear(); remoteCache.put(1, "word1 word2 word3"); remoteCache.put(2, "word1 word2"); remoteCache.put(3, "word1"); addScripts(STREAM); Map<String, Long> results = remoteCache.execute(STREAM, 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))); }
@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))); }
@Test @InSequence(2) @SuppressWarnings("unchecked") public void shouldGatherNodeNamesInRemoteTasks() throws Exception { Object resultObject = rcm1.getCache().execute(DistributedDeploymentTestServerTask.NAME, Collections.emptyMap()); assertNotNull(resultObject); List<String> result = (List<String>) resultObject; assertEquals(2, result.size()); assertTrue("result list does not contain expected items.", result.containsAll(asList("node0", "node1"))); }
@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")); }
@Test @SuppressWarnings("unchecked") public void shouldExecuteMapReduceOnReplCacheViaTask() throws Exception { RemoteCache remoteCache = managers.get(1).getCache(DistributedMapReduceServerTask.CACHE_NAME); remoteCache.put(1, "word1 word2 word3"); remoteCache.put(2, "word1 word2"); remoteCache.put(3, "word1"); List<Map<String, Long>> result = (List<Map<String, Long>>)remoteCache.execute(DistributedMapReduceServerTask.NAME, Collections.emptyMap()); assertEquals(2, result.size()); verifyMapReduceResult(result.get(0)); verifyMapReduceResult(result.get(1)); }
@Test @Ignore(value="Is disabled until ISPN-6173 is fixed.") public void shouldExecuteMapReduceViaJavaScriptInTask() throws Exception { RemoteCache remoteCache = managers.get(1).getCache(DistributedJSExecutingServerTask.CACHE_NAME); remoteCache.put(1, "word1 word2 word3"); remoteCache.put(2, "word1 word2"); remoteCache.put(3, "word1"); List<Map<String, Long>> result = (List<Map<String, Long>>)remoteCache.execute(DistributedJSExecutingServerTask.NAME, Collections.emptyMap()); assertEquals(2, result.size()); verifyMapReduceResult(result.get(0)); verifyMapReduceResult(result.get(1)); }
@Test @WithRunningServer({@RunningServer(name = "standalone-customtask")}) public void shouldExecuteMapReduceViaTask() 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(LocalMapReduceServerTask.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()); }
@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); }
@Test public void testStreamingScript() throws IOException { addScripts("stream.js"); RemoteCache<String, String> rc = remoteCacheManager.getCache("off-heap-default"); rc.clear(); rc.put("key1", "Lorem ipsum dolor sit amet"); rc.put("key2", "consectetur adipiscing elit"); rc.put("key3", "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua"); Map<String, Long> result = rc.execute("stream.js", Collections.emptyMap()); assertEquals(19, result.size()); }
@Test @InSequence(3) public void testTaskUndeploy() { deployer.undeploy("node1"); deployer.undeploy("node2"); exceptionRule.expect(HotRodClientException.class); exceptionRule.expectMessage("ISPN027002"); rcm1.getCache().execute(DistributedDeploymentTestServerTask.NAME, Collections.emptyMap()); } }
@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()); }
@Test public void shouldThrowException() throws Exception { SecurityConfigurationHelper config = new SecurityConfigurationHelper("DIGEST-MD5"); config.forIspnServer(server).withServerName("node0"); config.forCredentials(ADMIN_LOGIN, ADMIN_PASSWD); RemoteCacheManager rcm = new RemoteCacheManager(config.build(), true); RemoteCache remoteCache = rcm.getCache(LocalAuthTestServerTask.CACHE_NAME); exceptionRule.expect(HotRodClientException.class); exceptionRule.expectMessage("lacks 'EXEC' permission"); remoteCache.execute(LocalAuthTestServerTask.NAME, Collections.emptyMap()); } }
@Test public void shouldPassWithAuth() throws Exception { SecurityConfigurationHelper config = new SecurityConfigurationHelper("DIGEST-MD5"); config.forIspnServer(server).withServerName("node0"); config.forCredentials(EXECUTOR_LOGIN, EXECUTOR_PASSWORD); RemoteCacheManager rcm = new RemoteCacheManager(config.build(), true); RemoteCache remoteCache = rcm.getCache(LocalAuthTestServerTask.CACHE_NAME); String result = (String) remoteCache.execute(LocalAuthTestServerTask.NAME, Collections.emptyMap()); assertEquals(LocalAuthTestServerTask.EXECUTED_VALUE, result); assertEquals(true, remoteCache.get(LocalAuthTestServerTask.KEY)); }
@Test public void shouldThrowException() throws Exception { SecurityConfigurationHelper config = new SecurityConfigurationHelper("DIGEST-MD5"); config.forIspnServer(server1).withServerName("node0"); config.forCredentials(ADMIN_LOGIN, ADMIN_PASSWD); RemoteCacheManager rcm = new RemoteCacheManager(config.build(), true); RemoteCache remoteCache = rcm.getCache(DistributedAuthServerTask.CACHE_NAME); exceptionRule.expect(HotRodClientException.class); exceptionRule.expectMessage("lacks 'EXEC' permission"); remoteCache.execute(DistributedAuthServerTask.NAME, Collections.emptyMap()); rcm.stop(); } }
@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)); }