public DistributedExecutorMassIndexer(AdvancedCache cache, SearchIntegrator searchIntegrator, KeyTransformationHandler keyTransformationHandler, TimeService timeService) { this.cache = cache; this.searchIntegrator = searchIntegrator; this.indexUpdater = new IndexUpdater(searchIntegrator, keyTransformationHandler, timeService); this.executor = new DefaultExecutorService(cache); }
public DistributedExecutorMassIndexer(AdvancedCache cache, SearchIntegrator searchIntegrator) { this.cache = cache; this.searchIntegrator = searchIntegrator; this.indexUpdater = new IndexUpdater(cache); this.executor = new DefaultExecutorService(cache); }
protected DistributedExecutorService createDES(Cache<?,?> cache){ ExecutorService executorService = Executors.newCachedThreadPool(getTestThreadFactory("LocalExecutor")); DistributedExecutorService des = new DefaultExecutorService(cache, executorService, true); cleanupService = des; return des; }
public void testImproperMasterCacheForDistributedExecutor() { expectException(IllegalArgumentException.class, () -> new DefaultExecutorService(null)); }
@Test(expectedExceptions = CacheConfigurationException.class) public void testDistributedExecutor() { new DefaultExecutorService(cache()).submit(() -> null); }
@Override public <T> CompletableFuture<T> execute(String taskName, TaskContext context) { Cache<?, ?> masterCacheNode = context.getCache().get(); DefaultExecutorService des = new DefaultExecutorService(masterCacheNode); try { List<CompletableFuture<T>> tasks = des.submitEverywhere(new DistributedServerTask<>(taskName, context.getParameters())); // noinspection unchecked return (CompletableFuture<T>) CompletableFutures.sequence(tasks); } finally { des.shutdown(); } }
public void testBasicInvocation() throws Exception { DistributedExecutorService des = new DefaultExecutorService(c1); try { DistributedExecutionCompletionService<Integer> decs = new DistributedExecutionCompletionService<>(des); decs.submit(new SimpleCallable()); CompletableFuture<Integer> future = decs.take(); Integer r = future.get(); AssertJUnit.assertEquals(1, r.intValue()); } finally { des.shutdownNow(); } }
public void testBasicInvocationWithBlockingQueue() throws Exception { DistributedExecutorService des = new DefaultExecutorService(c1); try { BlockingQueue<CompletableFuture<Integer>> queue = new ArrayBlockingQueue<>(10); DistributedExecutionCompletionService<Integer> decs = new DistributedExecutionCompletionService<>(des, queue); decs.submit(new SimpleCallable()); CompletableFuture<Integer> future = decs.take(); Integer r = future.get(); AssertJUnit.assertEquals((Integer) 1, r); } finally { des.shutdownNow(); } }
public void testImproperLocalExecutorServiceForDistributedExecutor() { EmbeddedCacheManager cacheManager = TestCacheManagerFactory.createCacheManager(false); try { Cache<Object, Object> cache = cacheManager.getCache(); expectException(IllegalArgumentException.class, () -> new DefaultExecutorService(cache, null)); } finally { TestingUtil.killCacheManagers(cacheManager); } }
public void testBasicInvocationWithNullTask() throws Exception { DistributedExecutorService des = new DefaultExecutorService(c1); try { DistributedExecutionCompletionService<Integer> decs = new DistributedExecutionCompletionService<>(des); expectException(NullPointerException.class, () -> decs.submit(null)); } finally { des.shutdownNow(); } }
public void testBasicInvocationWithNullRunnable() throws Exception { DistributedExecutorService des = new DefaultExecutorService(c1); try { DistributedExecutionCompletionService<Integer> decs = new DistributedExecutionCompletionService<>(des); Integer result = 5; expectException(NullPointerException.class, () -> decs.submit(null, result)); } finally { des.shutdownNow(); } }
public void testBasicInvocationWithRunnable() throws Exception { DistributedExecutorService des = new DefaultExecutorService(c1); try { DistributedExecutionCompletionService<Integer> decs = new DistributedExecutionCompletionService<>(des); Integer result = 5; decs.submit(new SimpleRunnable(), result); CompletableFuture<Integer> future = decs.take(); Integer r = future.get(); AssertJUnit.assertEquals(result, r); } finally { des.shutdownNow(); } }
public void testBasicPollInvocation() throws Exception { DistributedExecutorService des = new DefaultExecutorService(c1); DistributedExecutionCompletionService<Integer> decs = new DistributedExecutionCompletionService<>(des); try { decs.submit(new SimpleCallable()); CompletableFuture<Integer> callable = decs.poll(1000, TimeUnit.MILLISECONDS); AssertJUnit.assertEquals((Integer) 1, callable.get()); } finally { des.shutdownNow(); } }
public void testBasicPollInvocationWithSleepingCallable() throws Exception { DistributedExecutorService des = new DefaultExecutorService(c1); DistributedExecutionCompletionService<Integer> decs = new DistributedExecutionCompletionService<>(des); try { decs.submit(new SimpleCallable(true, 5000)); CompletableFuture<Integer> callable = decs.poll(); AssertJUnit.assertNull(callable); } finally { des.shutdownNow(); } }
public void testBasicPollInvocationWithTimeout() throws Exception { DistributedExecutorService des = new DefaultExecutorService(c1); DistributedExecutionCompletionService<Integer> decs = new DistributedExecutionCompletionService<>(des); try { decs.submit(new SimpleCallable(true,5000)); CompletableFuture<Integer> callable = decs.poll(10, TimeUnit.MILLISECONDS); AssertJUnit.assertNull(callable); } finally { des.shutdownNow(); } }
public void testDistributedExecutorRealShutdown() { ConfigurationBuilder config = TestCacheManagerFactory.getDefaultCacheConfiguration(true); config.clustering().cacheMode(CacheMode.REPL_SYNC); EmbeddedCacheManager cacheManager = TestCacheManagerFactory.createClusteredCacheManager(config); ExecutorService service = new WithinThreadExecutor(); try { Cache<Object, Object> cache = cacheManager.getCache(); DistributedExecutorService des = new DefaultExecutorService(cache, service); des.shutdown(); assert des.isShutdown(); assert des.isTerminated(); assert !service.isShutdown(); } finally { TestingUtil.killCacheManagers(cacheManager); service.shutdown(); } }
private void addSelfToTopologyView(EmbeddedCacheManager cacheManager) { addressCache = cacheManager.getCache(configuration.topologyCacheName()); clusterAddress = cacheManager.getAddress(); address = new ServerAddress(configuration.publicHost(), configuration.publicPort()); distributedExecutorService = new DefaultExecutorService(addressCache); viewChangeListener = new CrashedMemberDetectorListener(addressCache, this); cacheManager.addListener(viewChangeListener); topologyChangeListener = new ReAddMyAddressListener(addressCache, clusterAddress, address); addressCache.addListener(topologyChangeListener); // Map cluster address to server endpoint address log.debugf("Map %s cluster address with %s server endpoint in address cache", clusterAddress, address); // Guaranteed delivery required since if data is lost, there won't be // any further cache calls, so negative acknowledgment can cause issues. addressCache.getAdvancedCache().withFlags(Flag.SKIP_CACHE_LOAD, Flag.GUARANTEED_DELIVERY) .put(clusterAddress, address); }
public void testStoppedCacheForDistributedExecutor() { ConfigurationBuilder config = TestCacheManagerFactory.getDefaultCacheConfiguration(true); config.clustering().cacheMode(CacheMode.REPL_SYNC); EmbeddedCacheManager cacheManager = TestCacheManagerFactory.createClusteredCacheManager(config); try { Cache<Object, Object> cache = cacheManager.getCache(); cache.stop(); expectException(IllegalStateException.class, () -> new DefaultExecutorService(cache)); } finally { TestingUtil.killCacheManagers(cacheManager); } }
public void testDistributedExecutorShutDown() { ConfigurationBuilder config = TestCacheManagerFactory.getDefaultCacheConfiguration(true); config.clustering().cacheMode(CacheMode.REPL_SYNC); EmbeddedCacheManager cacheManager = TestCacheManagerFactory.createClusteredCacheManager(config); try { Cache<Object, Object> cache = cacheManager.getCache(); DistributedExecutorService des = new DefaultExecutorService(cache); des.shutdown(); assert des.isShutdown(); assert des.isTerminated(); } finally { TestingUtil.killCacheManagers(cacheManager); } }
public void testDistributedExecutorShutDownNow() { ConfigurationBuilder config = TestCacheManagerFactory.getDefaultCacheConfiguration(true); config.clustering().cacheMode(CacheMode.REPL_SYNC); EmbeddedCacheManager cacheManager = TestCacheManagerFactory.createClusteredCacheManager(config); try { Cache<Object, Object> cache = cacheManager.getCache(); DistributedExecutorService des = new DefaultExecutorService(cache); assert !des.isShutdown(); assert !des.isTerminated(); des.shutdownNow(); assert des.isShutdown(); assert des.isTerminated(); } finally { TestingUtil.killCacheManagers(cacheManager); } }