com.google.common.util.concurrent.Uninterruptibles Java Examples
The following examples show how to use
com.google.common.util.concurrent.Uninterruptibles.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FlutterDartAnalysisServer.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Nullable public SourceChange setWidgetPropertyValue(int propertyId, FlutterWidgetPropertyValue value) { final CountDownLatch latch = new CountDownLatch(1); final AtomicReference<SourceChange> result = new AtomicReference<>(); final String id = analysisService.generateUniqueId(); synchronized (responseConsumers) { responseConsumers.put(id, (resultObject) -> { try { final JsonObject propertiesObject = resultObject.getAsJsonObject("change"); result.set(SourceChange.fromJson(propertiesObject)); } catch (Throwable ignored) { } latch.countDown(); }); } final JsonObject request = FlutterRequestUtilities.generateFlutterSetWidgetPropertyValue(id, propertyId, value); analysisService.sendRequest(id, request); Uninterruptibles.awaitUninterruptibly(latch, 100, TimeUnit.MILLISECONDS); return result.get(); }
Example #2
Source File: TestSQSObservableQueue.java From conductor with Apache License 2.0 | 6 votes |
@Test public void test() { List<Message> messages = new LinkedList<>(); Observable.range(0, 10).forEach((Integer x) -> messages.add(new Message("" + x, "payload: " + x, null))); assertEquals(10, messages.size()); SQSObservableQueue queue = mock(SQSObservableQueue.class); when(queue.getOrCreateQueue()).thenReturn("junit_queue_url"); Answer<?> answer = (Answer<List<Message>>) invocation -> Collections.emptyList(); when(queue.receiveMessages()).thenReturn(messages).thenAnswer(answer); when(queue.getOnSubscribe()).thenCallRealMethod(); when(queue.observe()).thenCallRealMethod(); List<Message> found = new LinkedList<>(); Observable<Message> observable = queue.observe(); assertNotNull(observable); observable.subscribe(found::add); Uninterruptibles.sleepUninterruptibly(1000, TimeUnit.MILLISECONDS); assertEquals(messages.size(), found.size()); assertEquals(messages, found); }
Example #3
Source File: JpaThreadFactoryTest.java From activejpa with Apache License 2.0 | 6 votes |
@Test public void shouldCloseOpenTransactionOnException() { final DummyModel model = new DummyModel("value1", "value2", "value3"); model.persist(); final AtomicReference<EntityTransaction> transaction = new AtomicReference<>(); Runnable runnable = new Runnable() { @Override public void run() { transaction.set(DummyModel.beginTxn()); throw new RuntimeException(); } }; Thread thread = new ActiveJpaThreadFactory().newThread(runnable); thread.run(); Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS); assertFalse(transaction.get().isActive()); }
Example #4
Source File: TheDataGroup.java From streams with Apache License 2.0 | 6 votes |
@Override public DemographicsAppendResponse appendDemographics(AppendRequest request) { try { RestCall call = restClient .doPost(baseUrl() + "sync/append/demographics") .body(request) .ignoreErrors(); String responseJson = call.getResponseAsString(); DemographicsAppendResponse response = parser.parse(responseJson, DemographicsAppendResponse.class); return response; } catch( Exception e ) { LOGGER.error("Exception", e); return new DemographicsAppendResponse(); } finally { Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS); } }
Example #5
Source File: Http1ClientCodecUnitTest.java From xio with Apache License 2.0 | 6 votes |
@Test public void testFullResponse() throws Exception { outputReceived = new CountDownLatch(1); ByteBuf body = ByteBufUtil.writeUtf8(UnpooledByteBufAllocator.DEFAULT, "response"); FullHttpResponse responseIn = new DefaultFullHttpResponse(HTTP_1_1, OK, body); channel.writeInbound(responseIn); channel.runPendingTasks(); // blocks Uninterruptibles.awaitUninterruptibly(outputReceived); Response responseOut = responses.remove(0); assertTrue(responseOut != null); assertTrue(responseOut instanceof FullResponse); assertEquals("HTTP/1.1", responseOut.version()); assertEquals(OK, responseOut.status()); assertTrue(responseOut.hasBody()); assertFalse(responseOut.body() == null); assertEquals(body, responseOut.body()); }
Example #6
Source File: FullContact.java From streams with Apache License 2.0 | 6 votes |
@Override public EnrichPersonResponse enrichPerson(EnrichPersonRequest request) { try { String requestJson = serializer.serialize(request); RestCall call = restClient .doPost(baseUrl() + "person.enrich") .accept("application/json") .contentType("application/json") .ignoreErrors() .body(new StringReader(requestJson)); String responseJson = call.getResponseAsString(); EnrichPersonResponse response = parser.parse(responseJson, EnrichPersonResponse.class); return response; } catch( Exception e ) { LOGGER.error("Exception", e); return new EnrichPersonResponse().withMessage(e.getMessage()); } finally { Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS); } }
Example #7
Source File: StandardKernel.java From openAGV with Apache License 2.0 | 6 votes |
@Override public void run() { // Wait until terminated. terminationSemaphore.acquireUninterruptibly(); LOG.info("Terminating..."); // Sleep a bit so clients have some time to receive an event for the // SHUTDOWN state change and shut down gracefully themselves. Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS); // Shut down all kernel extensions. LOG.debug("Shutting down kernel extensions..."); for (KernelExtension extension : kernelExtensions) { extension.terminate(); } kernelExecutor.shutdown(); LOG.info("Kernel thread finished."); }
Example #8
Source File: Hadoop21YarnNMClient.java From twill with Apache License 2.0 | 6 votes |
@Override public void cancel() { LOG.info("Request to stop container {}.", container.getId()); try { nmClient.stopContainer(container.getId(), container.getNodeId()); while (true) { ContainerStatus status = nmClient.getContainerStatus(container.getId(), container.getNodeId()); LOG.trace("Container status: {} {}", status, status.getDiagnostics()); if (status.getState() == ContainerState.COMPLETE) { break; } Uninterruptibles.sleepUninterruptibly(200, TimeUnit.MILLISECONDS); } LOG.info("Container {} stopped.", container.getId()); } catch (Exception e) { LOG.error("Fail to stop container {}", container.getId(), e); throw Throwables.propagate(e); } }
Example #9
Source File: LoopbackCommunicationAdapter.java From openAGV with Apache License 2.0 | 6 votes |
/** * Simulates an operation. * 模拟操作 * * @param operation A operation * @throws InterruptedException If an exception occured while simulating */ private void simulateOperation(String operation) { requireNonNull(operation, "operation"); if (isTerminated()) { return; } LOG.debug("Operating..."); final int operatingTime = getProcessModel().getOperatingTime(); getProcessModel().setVehicleState(Vehicle.State.EXECUTING); for (int timePassed = 0; timePassed < operatingTime && !isTerminated(); timePassed += simAdvanceTime) { Uninterruptibles.sleepUninterruptibly(ADVANCE_TIME, TimeUnit.MILLISECONDS); getProcessModel().getVelocityController().advanceTime(simAdvanceTime); } if (operation.equals(getProcessModel().getLoadOperation())) { // Update load handling devices as defined by this operation getProcessModel().setVehicleLoadHandlingDevices( Arrays.asList(new LoadHandlingDevice(LHD_NAME, true))); } else if (operation.equals(getProcessModel().getUnloadOperation())) { getProcessModel().setVehicleLoadHandlingDevices( Arrays.asList(new LoadHandlingDevice(LHD_NAME, false))); } }
Example #10
Source File: AdjustableRateLimiter.java From neural with MIT License | 6 votes |
static SleepingStopwatch createFromSystemTimer() { return new SleepingStopwatch() { final Stopwatch stopwatch = Stopwatch.createStarted(); @Override protected long readMicros() { return stopwatch.elapsed(MICROSECONDS); } @Override protected void sleepMicrosUninterruptibly(long micros) { if (micros > 0) { Uninterruptibles.sleepUninterruptibly(micros, MICROSECONDS); } } }; }
Example #11
Source File: CacheLoadingTest.java From caffeine with Apache License 2.0 | 6 votes |
/** * On a successful concurrent computation, only one thread does the work, but all the threads get * the same result. */ private static void testConcurrentLoadingDefault(Caffeine<Object, Object> builder) throws InterruptedException { int count = 10; final AtomicInteger callCount = new AtomicInteger(); final CountDownLatch startSignal = new CountDownLatch(count + 1); final Object result = new Object(); LoadingCache<String, Object> cache = CaffeinatedGuava.build(builder, new CacheLoader<String, Object>() { @Override public Object load(String key) { callCount.incrementAndGet(); assertTrue(Uninterruptibles.awaitUninterruptibly(startSignal, 300, TimeUnit.SECONDS)); return result; } }); List<Object> resultArray = doConcurrentGet(cache, "bar", count, startSignal); assertEquals(1, callCount.get()); for (int i = 0; i < count; i++) { assertSame("result(" + i + ") didn't match expected", result, resultArray.get(i)); } }
Example #12
Source File: Http2ClientCodecUnitTest.java From xio with Apache License 2.0 | 6 votes |
@Test public void testFullResponse() throws Exception { outputReceived = new CountDownLatch(1); Http2Headers headers = new DefaultHttp2Headers().status("200"); Http2Response responseIn = Http2Response.build(1, headers, true); channel.writeInbound(responseIn); channel.runPendingTasks(); // blocks Uninterruptibles.awaitUninterruptibly(outputReceived); Response responseOut = responses.remove(0); assertTrue(responseOut != null); assertTrue(responseOut instanceof FullResponse); assertEquals("h2", responseOut.version()); assertEquals(OK, responseOut.status()); assertFalse(responseOut.hasBody()); assertEquals(1, responseOut.streamId()); }
Example #13
Source File: UnixGlob.java From bazel with Apache License 2.0 | 6 votes |
List<Path> globUninterruptible( Path base, Collection<String> patterns, boolean excludeDirectories, Predicate<Path> dirPred, FilesystemCalls syscalls) throws IOException, BadPattern { try { return Uninterruptibles.getUninterruptibly( globAsync(base, patterns, excludeDirectories, dirPred, syscalls)); } catch (ExecutionException e) { Throwable cause = e.getCause(); Throwables.propagateIfPossible(cause, IOException.class); Throwables.propagateIfPossible(cause, BadPattern.class); throw new RuntimeException(e); } }
Example #14
Source File: TheDataGroup.java From streams with Apache License 2.0 | 6 votes |
@Override public MobileAppendResponse appendMobile(AppendRequest request) { try { RestCall call = restClient .doPost(baseUrl() + "sync/append/mobile") .body(request) .ignoreErrors(); String responseJson = call.getResponseAsString(); MobileAppendResponse response = parser.parse(responseJson, MobileAppendResponse.class); return response; } catch( Exception e ) { LOGGER.error("Exception", e); return new MobileAppendResponse(); } finally { Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS); } }
Example #15
Source File: AbstractFuture.java From hadoop-ozone with Apache License 2.0 | 6 votes |
public static <V> V getDone(Future<V> future) throws ExecutionException { /* * We throw IllegalStateException, since the call could succeed later. * Perhaps we "should" throw IllegalArgumentException, since the call * could succeed with a different argument. Those exceptions' docs * suggest that either is acceptable. Google's Java Practices page * recommends IllegalArgumentException here, in part to keep its * recommendation simple: Static methods should throw * IllegalStateException only when they use static state. * * * Why do we deviate here? The answer: We want for fluentFuture.getDone() * to throw the same exception as Futures.getDone(fluentFuture). */ Preconditions.checkState(future.isDone(), "Future was expected to be " + "done:" + " %s", future); return Uninterruptibles.getUninterruptibly(future); }
Example #16
Source File: ConcurrencyLimitServerInterceptorTest.java From concurrency-limits with Apache License 2.0 | 6 votes |
@Test public void releaseOnCancellation() { // Setup server startServer((req, observer) -> { Uninterruptibles.sleepUninterruptibly(2, TimeUnit.SECONDS); observer.onNext("delayed_response"); observer.onCompleted(); }); ListenableFuture<String> future = ClientCalls.futureUnaryCall(channel.newCall(METHOD_DESCRIPTOR, CallOptions.DEFAULT), "foo"); Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS); future.cancel(true); // Verify Mockito.verify(limiter, Mockito.times(1)).acquire(Mockito.isA(GrpcServerRequestContext.class)); Mockito.verify(listener.getResult().get(), Mockito.times(0)).onIgnore(); Mockito.verify(listener.getResult().get(), Mockito.timeout(2000).times(1)).onSuccess(); verifyCounts(0, 0, 1, 0); }
Example #17
Source File: Sprinklr.java From streams with Apache License 2.0 | 6 votes |
@Override public PartnerAccountsResponse getPartnerAccounts() { try { ObjectMap requestMap = new ObjectMap(); requestMap.put("types", "PARTNER_ACCOUNTS"); RestCall call = restClient .doGet(baseUrl() + "v1/bootstrap/resources") .queryIfNE(requestMap) .ignoreErrors(); String responseJson = call.getResponseAsString(); PartnerAccountsResponse response = parser.parse(responseJson, PartnerAccountsResponse.class); return response; } catch (Exception e) { LOGGER.error("Exception", e); return new PartnerAccountsResponse(); } finally { Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS); } }
Example #18
Source File: TheDataGroup.java From streams with Apache License 2.0 | 6 votes |
@Override public LookupResponse lookupIp(IpLookupRequest request) { try { RestCall call = restClient .doPost(baseUrl() + "sync/lookup/ip") .body(request) .ignoreErrors(); String responseJson = call.getResponseAsString(); LookupResponse response = parser.parse(responseJson, LookupResponse.class); return response; } catch( Exception e ) { LOGGER.error("Exception", e); return new LookupResponse(); } finally { Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS); } }
Example #19
Source File: LLRealtimeSegmentDataManager.java From incubator-pinot with Apache License 2.0 | 5 votes |
/** * Stop the consuming thread. */ public void stop() throws InterruptedException { _shouldStop = true; // This method could be called either when we get an ONLINE transition or // when we commit a segment and replace the realtime segment with a committed // one. In the latter case, we don't want to call join. if (Thread.currentThread() != _consumerThread) { Uninterruptibles.joinUninterruptibly(_consumerThread, 10, TimeUnit.MINUTES); if (_consumerThread.isAlive()) { segmentLogger.warn("Failed to stop consumer thread within 10 minutes"); } } }
Example #20
Source File: GPlusUserActivityProvider.java From streams with Apache License 2.0 | 5 votes |
/** * Retrieve recent activity from a list of accounts. * @param args args * @throws Exception Exception */ public static void main(String[] args) throws Exception { Preconditions.checkArgument(args.length >= 2); String configfile = args[0]; String outfile = args[1]; File file = new File(configfile); assert (file.exists()); Config conf = ConfigFactory.parseFileAnySyntax(file, ConfigParseOptions.defaults().setAllowMissing(false)); StreamsConfigurator.addConfig(conf); StreamsConfiguration streamsConfiguration = StreamsConfigurator.detectConfiguration(); GPlusUserActivityProviderConfiguration config = new ComponentConfigurator<>(GPlusUserActivityProviderConfiguration.class).detectConfiguration(); GPlusUserActivityProvider provider = new GPlusUserActivityProvider(config); Gson gson = new Gson(); PrintStream outStream = new PrintStream(new BufferedOutputStream(new FileOutputStream(outfile))); provider.prepare(config); provider.startStream(); do { Uninterruptibles.sleepUninterruptibly(streamsConfiguration.getBatchFrequencyMs(), TimeUnit.MILLISECONDS); for (StreamsDatum datum : provider.readCurrent()) { String json; if (datum.getDocument() instanceof String) { json = (String) datum.getDocument(); } else { json = gson.toJson(datum.getDocument()); } outStream.println(json); } } while ( provider.isRunning()); provider.cleanUp(); outStream.flush(); }
Example #21
Source File: ServletWrapperDelegatorServlet.java From nomulus with Apache License 2.0 | 5 votes |
@Override public void service(final HttpServletRequest req, final HttpServletResponse rsp) throws ServletException, IOException { FutureTask<Void> task = new FutureTask<>(new Callable<Void>() { @Nullable @Override public Void call() throws ServletException, IOException { // Simulate the full filter chain with the servlet at the end. final Iterator<Class<? extends Filter>> filtersIter = filterClasses.iterator(); FilterChain filterChain = new FilterChain() { @Override public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException { if (filtersIter.hasNext()) { instantiate(filtersIter.next()).doFilter(request, response, this); } else { instantiate(servletClass).service(request, response); } }}; filterChain.doFilter(req, rsp); return null; }}); requestQueue.add(task); try { Uninterruptibles.getUninterruptibly(task); } catch (ExecutionException e) { throwIfInstanceOf(e.getCause(), ServletException.class); throwIfInstanceOf(e.getCause(), IOException.class); throw new RuntimeException(e.getCause()); } }
Example #22
Source File: Connection.java From bisq with GNU Affero General Public License v3.0 | 5 votes |
public void shutDown(CloseConnectionReason closeConnectionReason, @Nullable Runnable shutDownCompleteHandler) { log.debug("shutDown: nodeAddressOpt={}, closeConnectionReason={}", this.peersNodeAddressOptional.orElse(null), closeConnectionReason); if (!stopped) { String peersNodeAddress = peersNodeAddressOptional.map(NodeAddress::toString).orElse("null"); log.debug("\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n" + "ShutDown connection:" + "\npeersNodeAddress=" + peersNodeAddress + "\ncloseConnectionReason=" + closeConnectionReason + "\nuid=" + uid + "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"); if (closeConnectionReason.sendCloseMessage) { new Thread(() -> { try { String reason = closeConnectionReason == CloseConnectionReason.RULE_VIOLATION ? getRuleViolation().name() : closeConnectionReason.name(); sendMessage(new CloseConnectionMessage(reason)); stopped = true; //noinspection UnstableApiUsage Uninterruptibles.sleepUninterruptibly(200, TimeUnit.MILLISECONDS); } catch (Throwable t) { log.error(t.getMessage()); t.printStackTrace(); } finally { stopped = true; UserThread.execute(() -> doShutDown(closeConnectionReason, shutDownCompleteHandler)); } }, "Connection:SendCloseConnectionMessage-" + this.uid).start(); } else { stopped = true; doShutDown(closeConnectionReason, shutDownCompleteHandler); } } else { //TODO find out why we get called that log.debug("stopped was already at shutDown call"); UserThread.execute(() -> doShutDown(closeConnectionReason, shutDownCompleteHandler)); } }
Example #23
Source File: SevenDaySearchProvider.java From streams with Apache License 2.0 | 5 votes |
@Override public Iterator<Tweet> call() throws Exception { prepare(config); startStream(); do { Uninterruptibles.sleepUninterruptibly(streamsConfiguration.getBatchFrequencyMs(), TimeUnit.MILLISECONDS); } while ( isRunning()); cleanUp(); return providerQueue.stream().map( x -> ((Tweet)x.getDocument())).distinct().iterator(); }
Example #24
Source File: CloudSqlInstance.java From cloud-sql-jdbc-socket-factory with Apache License 2.0 | 5 votes |
/** * Returns the current data related to the instance from {@link #performRefresh()}. May block if * no valid data is currently available. */ private InstanceData getInstanceData() { ListenableFuture<InstanceData> instanceData; synchronized (instanceDataGuard) { instanceData = currentInstanceData; } try { // TODO(kvg): Let exceptions up to here before adding context return Uninterruptibles.getUninterruptibly(instanceData); } catch (ExecutionException ex) { Throwable cause = ex.getCause(); Throwables.throwIfUnchecked(cause); throw new RuntimeException(cause); } }
Example #25
Source File: DefaultTimeoutControllerTest.java From armeria with Apache License 2.0 | 5 votes |
@Test void cancelTimeout_afterDeadline() { timeoutController.scheduleTimeout(500); Uninterruptibles.sleepUninterruptibly(1000, TimeUnit.MILLISECONDS); assertThat(timeoutController.cancelTimeout()).isFalse(); assertThat(isTimeout).isTrue(); }
Example #26
Source File: InstagramRecentMediaProvider.java From streams with Apache License 2.0 | 5 votes |
/** * To use from command line: * * <p></p> * Supply (at least) the following required configuration in application.conf: * * <p></p> * instagram.clientKey * instagram.usersInfo.authorizedTokens * instagram.usersInfo.users * * <p></p> * Launch using: * * <p></p> * mvn exec:java \ * -Dexec.mainClass=org.apache.streams.instagram.provider.recentmedia.InstagramRecentMediaProvider \ * -Dexec.args="application.conf media.json.txt" * * @param args args * @throws Exception Exception */ public static void main(String[] args) throws Exception { Preconditions.checkArgument(args.length >= 2); String configfile = args[0]; String outfile = args[1]; Config reference = ConfigFactory.load(); File file = new File(configfile); assert (file.exists()); Config conf = ConfigFactory.parseFileAnySyntax(file, ConfigParseOptions.defaults().setAllowMissing(false)); StreamsConfigurator.addConfig(conf); StreamsConfiguration streamsConfiguration = StreamsConfigurator.detectConfiguration(); InstagramRecentMediaProviderConfiguration config = new ComponentConfigurator<>(InstagramRecentMediaProviderConfiguration.class).detectConfiguration(); InstagramRecentMediaProvider provider = new InstagramRecentMediaProvider(config); PrintStream outStream = new PrintStream(new BufferedOutputStream(new FileOutputStream(outfile))); provider.prepare(config); provider.startStream(); do { Uninterruptibles.sleepUninterruptibly(streamsConfiguration.getBatchFrequencyMs(), TimeUnit.MILLISECONDS); Iterator<StreamsDatum> iterator = provider.readCurrent().iterator(); while (iterator.hasNext()) { StreamsDatum datum = iterator.next(); String json; try { json = MAPPER.writeValueAsString(datum.getDocument()); outStream.println(json); } catch (JsonProcessingException ex) { System.err.println(ex.getMessage()); } } } while ( provider.isRunning()); provider.cleanUp(); outStream.flush(); }
Example #27
Source File: TaskPollExecutorTest.java From conductor with Apache License 2.0 | 5 votes |
@Test public void testTaskPollException() { Task task = testTask(); Worker worker = mock(Worker.class); when(worker.getPollingInterval()).thenReturn(3000); when(worker.getTaskDefName()).thenReturn("test"); when(worker.execute(any())).thenReturn(new TaskResult(task)); TaskClient taskClient = Mockito.mock(TaskClient.class); when(taskClient.pollTask(any(), any(), any())) .thenThrow(ConductorClientException.class) .thenReturn(task); TaskPollExecutor taskPollExecutor = new TaskPollExecutor(null, taskClient, 1, 1, "test-worker-"); CountDownLatch latch = new CountDownLatch(1); doAnswer(invocation -> { Object[] args = invocation.getArguments(); TaskResult result = (TaskResult) args[0]; assertEquals(IN_PROGRESS, result.getStatus()); assertEquals(task.getTaskId(), result.getTaskId()); latch.countDown(); return null; } ).when(taskClient).updateTask(any()); Executors.newSingleThreadScheduledExecutor() .scheduleAtFixedRate(() -> taskPollExecutor.pollAndExecute(worker), 0, 1, TimeUnit.SECONDS); Uninterruptibles.awaitUninterruptibly(latch); verify(taskClient).updateTask(any()); }
Example #28
Source File: TestSimpleEventProcessor.java From conductor with Apache License 2.0 | 5 votes |
@Test public void testEventProcessorWithNonRetriableError() { EventHandler eventHandler = new EventHandler(); eventHandler.setName(UUID.randomUUID().toString()); eventHandler.setActive(true); eventHandler.setEvent(event); Action completeTaskAction = new Action(); completeTaskAction.setAction(Type.complete_task); completeTaskAction.setComplete_task(new TaskDetails()); completeTaskAction.getComplete_task().setTaskRefName("task_x"); completeTaskAction.getComplete_task().setWorkflowId(UUID.randomUUID().toString()); completeTaskAction.getComplete_task().setOutput(new HashMap<>()); eventHandler.getActions().add(completeTaskAction); when(metadataService.getAllEventHandlers()).thenReturn(Collections.singletonList(eventHandler)); when(metadataService.getEventHandlersForEvent(event, true)).thenReturn(Collections.singletonList(eventHandler)); when(executionService.addEventExecution(any())).thenReturn(true); when(actionProcessor.execute(any(), any(), any(), any())).thenThrow(new ApplicationException(ApplicationException.Code.INVALID_INPUT, "some non-retriable error")); SimpleEventProcessor eventProcessor = new SimpleEventProcessor(executionService, metadataService, actionProcessor, eventQueues, jsonUtils, new TestConfiguration(), objectMapper); assertNotNull(eventProcessor.getQueues()); assertEquals(1, eventProcessor.getQueues().size()); Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS); verify(queue, atMost(1)).ack(any()); verify(queue, never()).publish(any()); }
Example #29
Source File: WorkflowTaskCoordinatorTests.java From conductor with Apache License 2.0 | 5 votes |
@Test public void testTaskException() { Worker worker = Worker.create("test", task -> { throw new NoSuchMethodError(); }); TaskClient client = Mockito.mock(TaskClient.class); WorkflowTaskCoordinator coordinator = new WorkflowTaskCoordinator.Builder() .withWorkers(worker) .withThreadCount(1) .withWorkerQueueSize(1) .withSleepWhenRetry(100000) .withUpdateRetryCount(1) .withTaskClient(client) .withWorkerNamePrefix("test-worker-") .build(); when(client.batchPollTasksInDomain(anyString(), isNull(), anyString(), anyInt(), anyInt())).thenReturn(ImmutableList.of(new Task())); when(client.ack(any(), any())).thenReturn(true); CountDownLatch latch = new CountDownLatch(1); doAnswer(invocation -> { assertEquals("test-worker-0", Thread.currentThread().getName()); Object[] args = invocation.getArguments(); TaskResult result = (TaskResult) args[0]; assertEquals(TaskResult.Status.FAILED, result.getStatus()); latch.countDown(); return null; } ).when(client).updateTask(any()); coordinator.init(); Uninterruptibles.awaitUninterruptibly(latch); Mockito.verify(client).updateTask(any()); }
Example #30
Source File: TestHAStateTransitions.java From hadoop with Apache License 2.0 | 5 votes |
/** * Test that transitioning a service to the state that it is already * in is a nop, specifically, an exception is not thrown. */ @Test(timeout = 300000) public void testTransitionToCurrentStateIsANop() throws Exception { Configuration conf = new Configuration(); conf.setLong(DFSConfigKeys.DFS_NAMENODE_PATH_BASED_CACHE_REFRESH_INTERVAL_MS, 1L); MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf) .nnTopology(MiniDFSNNTopology.simpleHATopology()) .numDataNodes(1) .build(); LinkedList<Thread> crmThreads = new LinkedList<Thread>(); try { cluster.waitActive(); addCrmThreads(cluster, crmThreads); cluster.transitionToActive(0); addCrmThreads(cluster, crmThreads); cluster.transitionToActive(0); addCrmThreads(cluster, crmThreads); cluster.transitionToStandby(0); addCrmThreads(cluster, crmThreads); cluster.transitionToStandby(0); addCrmThreads(cluster, crmThreads); } finally { cluster.shutdown(); } // Verify that all cacheReplicationMonitor threads shut down for (Thread thread : crmThreads) { Uninterruptibles.joinUninterruptibly(thread); } }