Search in sources :

Example 1 with ScriptingManager

use of org.infinispan.scripting.ScriptingManager in project infinispan by infinispan.

the class ExecTest method testRemoteMapReduceWithStreams.

@Test(enabled = false, dataProvider = "CacheModeProvider", description = "Disabling this test until the distributed scripts in DIST mode are fixed - ISPN-6173")
public void testRemoteMapReduceWithStreams(CacheMode cacheMode) throws Exception {
    String cacheName = "testRemoteMapReduce_Streams_dist_" + cacheMode.toString();
    ConfigurationBuilder builder = getDefaultClusteredCacheConfig(cacheMode, true);
    builder.encoding().key().mediaType(APPLICATION_OBJECT_TYPE);
    builder.encoding().value().mediaType(APPLICATION_OBJECT_TYPE);
    defineInAll(cacheName, builder);
    waitForClusterToForm(cacheName);
    RemoteCache<String, String> cache = clients.get(0).getCache(cacheName);
    ScriptingUtils.loadData(cache, "/macbeth.txt");
    ScriptingManager scriptingManager = manager(0).getGlobalComponentRegistry().getComponent(ScriptingManager.class);
    loadScript("/wordCountStream_dist.js", scriptingManager, "wordCountStream_dist.js");
    ArrayList<Map<String, Long>> results = cache.execute("wordCountStream_dist.js", new HashMap<String, String>());
    assertEquals(2, results.size());
    assertEquals(3202, results.get(0).size());
    assertEquals(3202, results.get(1).size());
    assertTrue(results.get(0).get("macbeth").equals(287L));
    assertTrue(results.get(1).get("macbeth").equals(287L));
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) ScriptingManager(org.infinispan.scripting.ScriptingManager) CommonsTestingUtil.loadFileAsString(org.infinispan.commons.test.CommonsTestingUtil.loadFileAsString) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.testng.annotations.Test) MultiHotRodServersTest(org.infinispan.client.hotrod.test.MultiHotRodServersTest)

Example 2 with ScriptingManager

use of org.infinispan.scripting.ScriptingManager in project infinispan by infinispan.

the class HotRodClientTestingUtil method withScript.

public static void withScript(EmbeddedCacheManager cm, String scriptPath, Consumer<String> f) {
    ScriptingManager scriptingManager = cm.getGlobalComponentRegistry().getComponent(ScriptingManager.class);
    String scriptName = scriptPath.replaceAll("\\/", "");
    try {
        loadScript(scriptName, scriptingManager, scriptPath);
        f.accept(scriptName);
    } finally {
        scriptingManager.removeScript(scriptName);
    }
}
Also used : ScriptingManager(org.infinispan.scripting.ScriptingManager) CommonsTestingUtil.loadFileAsString(org.infinispan.commons.test.CommonsTestingUtil.loadFileAsString)

Example 3 with ScriptingManager

use of org.infinispan.scripting.ScriptingManager in project infinispan by infinispan.

the class TasksResource method createScriptTask.

private CompletionStage<RestResponse> createScriptTask(RestRequest request) {
    String taskName = request.variables().get("taskName");
    EmbeddedCacheManager cacheManager = invocationHelper.getRestCacheManager().getInstance().withSubject(request.getSubject());
    ScriptingManager scriptingManager = SecurityActions.getGlobalComponentRegistry(cacheManager).getComponent(ScriptingManager.class);
    NettyRestResponse.Builder builder = new NettyRestResponse.Builder();
    ContentSource contents = request.contents();
    byte[] bytes = contents.rawContent();
    MediaType sourceType = request.contentType() == null ? APPLICATION_JAVASCRIPT : request.contentType();
    String script = StandardConversions.convertTextToObject(bytes, sourceType);
    return CompletableFuture.supplyAsync(() -> {
        Subject.doAs(request.getSubject(), (PrivilegedAction<Void>) () -> {
            scriptingManager.addScript(taskName, script);
            return null;
        });
        return builder.build();
    }, invocationHelper.getExecutor());
}
Also used : ContentSource(org.infinispan.rest.framework.ContentSource) ScriptingManager(org.infinispan.scripting.ScriptingManager) MediaType(org.infinispan.commons.dataconversion.MediaType) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) NettyRestResponse(org.infinispan.rest.NettyRestResponse)

Aggregations

ScriptingManager (org.infinispan.scripting.ScriptingManager)3 CommonsTestingUtil.loadFileAsString (org.infinispan.commons.test.CommonsTestingUtil.loadFileAsString)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 MultiHotRodServersTest (org.infinispan.client.hotrod.test.MultiHotRodServersTest)1 MediaType (org.infinispan.commons.dataconversion.MediaType)1 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)1 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)1 NettyRestResponse (org.infinispan.rest.NettyRestResponse)1 ContentSource (org.infinispan.rest.framework.ContentSource)1 Test (org.testng.annotations.Test)1