List of usage examples for java.util.concurrent.atomic AtomicBoolean getAndSet
public final boolean getAndSet(boolean newValue)
From source file:info.archinnov.achilles.it.TestAsyncDSLSimpleEntity.java
@Test public void should_dsl_update_value_async() throws Exception { //Given/* w w w .j a v a 2s . c om*/ final long id = RandomUtils.nextLong(0L, Long.MAX_VALUE); final Date date = buildDateKey(); final AtomicBoolean success = new AtomicBoolean(false); scriptExecutor.executeScriptTemplate("SimpleEntity/insert_single_row.cql", ImmutableMap.of("id", id, "table", "simple")); final CountDownLatch latch = new CountDownLatch(1); final CassandraLogAsserter logAsserter = new CassandraLogAsserter(); logAsserter.prepareLogLevel(ASYNC_LOGGER_STRING, "%msg - [%thread]%n"); //When manager.dsl().update().fromBaseTable().value_Set("new value").where().id_Eq(id).date_Eq(date) .ifValue_Eq("0 AM").withLwtResultListener(new LWTResultListener() { @Override public void onSuccess() { success.getAndSet(true); } @Override public void onError(LWTResult lwtResult) { } }).withResultSetAsyncListener(rs -> { LOGGER.info(CALLED); latch.countDown(); return rs; }).executeAsync(); //Then latch.await(); logAsserter.assertContains("Called - [achilles-default-executor"); }
From source file:info.archinnov.achilles.it.TestCRUDSimpleEntity.java
@Test public void should_insert_if_not_exists() throws Exception { //Given// www.java 2s . c om final long id = 100L; final Date date = buildDateKey(); scriptExecutor.executeScriptTemplate("SimpleEntity/insert_single_row.cql", ImmutableMap.of("id", id, "table", "simple")); final SimpleEntity entity = new SimpleEntity(id, date, "value"); final AtomicBoolean error = new AtomicBoolean(false); final AtomicLong currentId = new AtomicLong(0L); final LWTResultListener lwtListener = new LWTResultListener() { @Override public void onSuccess() { } @Override public void onError(LWTResult lwtResult) { error.getAndSet(true); currentId.getAndSet(lwtResult.currentValues().getTyped("id")); } }; //When manager.crud().insert(entity).ifNotExists().withLwtResultListener(lwtListener).execute(); //Then assertThat(error.get()).isTrue(); assertThat(currentId.get()).isEqualTo(id); }
From source file:info.archinnov.achilles.it.TestCRUDSimpleEntity.java
@Test public void should_delete_if_exists() throws Exception { //Given/*from ww w.ja v a 2 s .co m*/ final long id = RandomUtils.nextLong(0L, Long.MAX_VALUE); final Date date = buildDateKey(); final AtomicBoolean error = new AtomicBoolean(false); final AtomicBoolean applied = new AtomicBoolean(true); final LWTResultListener lwtListener = new LWTResultListener() { @Override public void onSuccess() { } @Override public void onError(LWTResult lwtResult) { error.getAndSet(true); applied.getAndSet(lwtResult.currentValues().getTyped("[applied]")); } }; //When manager.crud().deleteById(id, date).ifExists().withLwtResultListener(lwtListener).execute(); //Then assertThat(error.get()).isTrue(); assertThat(applied.get()).isFalse(); }
From source file:com.wellsandwhistles.android.redditsp.adapters.MainMenuListingManager.java
public MainMenuListingManager(@NonNull final AppCompatActivity activity, @NonNull final MainMenuSelectionListener listener, @NonNull final RedditAccount user) { General.checkThisIsUIThread();// ww w .j a va 2s. c o m mActivity = activity; mContext = activity.getApplicationContext(); Context context = activity; mListener = listener; final Drawable srIconPerson; final Drawable srIconEnvOpen; final Drawable srIconSend; final Drawable srIconStarFilled; final Drawable srIconCross; final Drawable srIconUpvote; final Drawable srIconDownvote; { final TypedArray attr = context.obtainStyledAttributes(new int[] { R.attr.srIconPerson, R.attr.srIconEnvOpen, R.attr.srIconSend, R.attr.srIconStarFilled, R.attr.srIconCross, R.attr.srIconUpvote, R.attr.srIconDownvote }); srIconPerson = ContextCompat.getDrawable(context, attr.getResourceId(0, 0)); srIconEnvOpen = ContextCompat.getDrawable(context, attr.getResourceId(1, 0)); srIconSend = ContextCompat.getDrawable(context, attr.getResourceId(2, 0)); srIconStarFilled = ContextCompat.getDrawable(context, attr.getResourceId(3, 0)); srIconCross = ContextCompat.getDrawable(context, attr.getResourceId(4, 0)); srIconUpvote = ContextCompat.getDrawable(context, attr.getResourceId(5, 0)); srIconDownvote = ContextCompat.getDrawable(context, attr.getResourceId(6, 0)); attr.recycle(); } mAdapter.appendToGroup(GROUP_MAIN_ITEMS, makeItem(R.string.mainmenu_frontpage, MainMenuFragment.MENU_MENU_ACTION_FRONTPAGE, null, true)); mAdapter.appendToGroup(GROUP_MAIN_ITEMS, makeItem(R.string.mainmenu_all, MainMenuFragment.MENU_MENU_ACTION_ALL, null, false)); mAdapter.appendToGroup(GROUP_MAIN_ITEMS, makeItem(R.string.mainmenu_custom_destination, MainMenuFragment.MENU_MENU_ACTION_CUSTOM, null, false)); if (!user.isAnonymous()) { final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); final EnumSet<MainMenuFragment.MainMenuUserItems> mainMenuUserItems = PrefsUtility .pref_menus_mainmenu_useritems(context, sharedPreferences); if (!mainMenuUserItems.isEmpty()) { if (PrefsUtility.pref_appearance_hide_username_main_menu(context, PreferenceManager.getDefaultSharedPreferences(context))) { mAdapter.appendToGroup(GROUP_USER_HEADER, new GroupedRecyclerViewItemListSectionHeaderView( context.getString(R.string.mainmenu_useritems))); } else { mAdapter.appendToGroup(GROUP_USER_HEADER, new GroupedRecyclerViewItemListSectionHeaderView(user.username)); } final AtomicBoolean isFirst = new AtomicBoolean(true); if (mainMenuUserItems.contains(MainMenuFragment.MainMenuUserItems.PROFILE)) mAdapter.appendToGroup(GROUP_USER_ITEMS, makeItem(R.string.mainmenu_profile, MainMenuFragment.MENU_MENU_ACTION_PROFILE, srIconPerson, isFirst.getAndSet(false))); if (mainMenuUserItems.contains(MainMenuFragment.MainMenuUserItems.INBOX)) mAdapter.appendToGroup(GROUP_USER_ITEMS, makeItem(R.string.mainmenu_inbox, MainMenuFragment.MENU_MENU_ACTION_INBOX, srIconEnvOpen, isFirst.getAndSet(false))); if (mainMenuUserItems.contains(MainMenuFragment.MainMenuUserItems.SUBMITTED)) mAdapter.appendToGroup(GROUP_USER_ITEMS, makeItem(R.string.mainmenu_submitted, MainMenuFragment.MENU_MENU_ACTION_SUBMITTED, srIconSend, isFirst.getAndSet(false))); if (mainMenuUserItems.contains(MainMenuFragment.MainMenuUserItems.SAVED)) mAdapter.appendToGroup(GROUP_USER_ITEMS, makeItem(R.string.mainmenu_saved, MainMenuFragment.MENU_MENU_ACTION_SAVED, srIconStarFilled, isFirst.getAndSet(false))); } } setPinnedSubreddits(); if (PrefsUtility.pref_appearance_show_blocked_subreddits_main_menu(context, PreferenceManager.getDefaultSharedPreferences(context))) { setBlockedSubreddits(); } if (!user.isAnonymous()) { showMultiredditsHeader(context); final LoadingSpinnerView multiredditsLoadingSpinnerView = new LoadingSpinnerView(context); final int paddingPx = General.dpToPixels(context, 30); multiredditsLoadingSpinnerView.setPadding(paddingPx, paddingPx, paddingPx, paddingPx); final GroupedRecyclerViewItemFrameLayout multiredditsLoadingItem = new GroupedRecyclerViewItemFrameLayout( multiredditsLoadingSpinnerView); mAdapter.appendToGroup(GROUP_MULTIREDDITS_ITEMS, multiredditsLoadingItem); } mAdapter.appendToGroup(GROUP_SUBREDDITS_HEADER, new GroupedRecyclerViewItemListSectionHeaderView( context.getString(R.string.mainmenu_header_subreddits_subscribed))); { final LoadingSpinnerView subredditsLoadingSpinnerView = new LoadingSpinnerView(context); final int paddingPx = General.dpToPixels(context, 30); subredditsLoadingSpinnerView.setPadding(paddingPx, paddingPx, paddingPx, paddingPx); final GroupedRecyclerViewItemFrameLayout subredditsLoadingItem = new GroupedRecyclerViewItemFrameLayout( subredditsLoadingSpinnerView); mAdapter.appendToGroup(GROUP_SUBREDDITS_ITEMS, subredditsLoadingItem); } }
From source file:org.quantumbadger.redreader.adapters.MainMenuListingManager.java
public MainMenuListingManager(@NonNull final AppCompatActivity activity, @NonNull final MainMenuSelectionListener listener, @NonNull final RedditAccount user) { General.checkThisIsUIThread();// w ww. j a va 2s. c o m mActivity = activity; mContext = activity.getApplicationContext(); Context context = activity; mListener = listener; final Drawable rrIconPerson; final Drawable rrIconEnvOpen; final Drawable rrIconSend; final Drawable rrIconStarFilled; final Drawable rrIconCross; final Drawable rrIconUpvote; final Drawable rrIconDownvote; { final TypedArray attr = context.obtainStyledAttributes(new int[] { R.attr.rrIconPerson, R.attr.rrIconEnvOpen, R.attr.rrIconSend, R.attr.rrIconStarFilled, R.attr.rrIconCross, R.attr.rrIconUpvote, R.attr.rrIconDownvote }); rrIconPerson = ContextCompat.getDrawable(context, attr.getResourceId(0, 0)); rrIconEnvOpen = ContextCompat.getDrawable(context, attr.getResourceId(1, 0)); rrIconSend = ContextCompat.getDrawable(context, attr.getResourceId(2, 0)); rrIconStarFilled = ContextCompat.getDrawable(context, attr.getResourceId(3, 0)); rrIconCross = ContextCompat.getDrawable(context, attr.getResourceId(4, 0)); rrIconUpvote = ContextCompat.getDrawable(context, attr.getResourceId(5, 0)); rrIconDownvote = ContextCompat.getDrawable(context, attr.getResourceId(6, 0)); attr.recycle(); } mAdapter.appendToGroup(GROUP_MAIN_ITEMS, makeItem(R.string.mainmenu_frontpage, MainMenuFragment.MENU_MENU_ACTION_FRONTPAGE, null, true)); mAdapter.appendToGroup(GROUP_MAIN_ITEMS, makeItem(R.string.mainmenu_all, MainMenuFragment.MENU_MENU_ACTION_ALL, null, false)); mAdapter.appendToGroup(GROUP_MAIN_ITEMS, makeItem(R.string.mainmenu_custom_destination, MainMenuFragment.MENU_MENU_ACTION_CUSTOM, null, false)); if (!user.isAnonymous()) { final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); final EnumSet<MainMenuFragment.MainMenuUserItems> mainMenuUserItems = PrefsUtility .pref_menus_mainmenu_useritems(context, sharedPreferences); if (!mainMenuUserItems.isEmpty()) { if (PrefsUtility.pref_appearance_hide_username_main_menu(context, PreferenceManager.getDefaultSharedPreferences(context))) { mAdapter.appendToGroup(GROUP_USER_HEADER, new GroupedRecyclerViewItemListSectionHeaderView( context.getString(R.string.mainmenu_useritems))); } else { mAdapter.appendToGroup(GROUP_USER_HEADER, new GroupedRecyclerViewItemListSectionHeaderView(user.username)); } final AtomicBoolean isFirst = new AtomicBoolean(true); if (mainMenuUserItems.contains(MainMenuFragment.MainMenuUserItems.PROFILE)) mAdapter.appendToGroup(GROUP_USER_ITEMS, makeItem(R.string.mainmenu_profile, MainMenuFragment.MENU_MENU_ACTION_PROFILE, rrIconPerson, isFirst.getAndSet(false))); if (mainMenuUserItems.contains(MainMenuFragment.MainMenuUserItems.INBOX)) mAdapter.appendToGroup(GROUP_USER_ITEMS, makeItem(R.string.mainmenu_inbox, MainMenuFragment.MENU_MENU_ACTION_INBOX, rrIconEnvOpen, isFirst.getAndSet(false))); if (mainMenuUserItems.contains(MainMenuFragment.MainMenuUserItems.SUBMITTED)) mAdapter.appendToGroup(GROUP_USER_ITEMS, makeItem(R.string.mainmenu_submitted, MainMenuFragment.MENU_MENU_ACTION_SUBMITTED, rrIconSend, isFirst.getAndSet(false))); if (mainMenuUserItems.contains(MainMenuFragment.MainMenuUserItems.SAVED)) mAdapter.appendToGroup(GROUP_USER_ITEMS, makeItem(R.string.mainmenu_saved, MainMenuFragment.MENU_MENU_ACTION_SAVED, rrIconStarFilled, isFirst.getAndSet(false))); if (mainMenuUserItems.contains(MainMenuFragment.MainMenuUserItems.HIDDEN)) mAdapter.appendToGroup(GROUP_USER_ITEMS, makeItem(R.string.mainmenu_hidden, MainMenuFragment.MENU_MENU_ACTION_HIDDEN, rrIconCross, isFirst.getAndSet(false))); if (mainMenuUserItems.contains(MainMenuFragment.MainMenuUserItems.UPVOTED)) mAdapter.appendToGroup(GROUP_USER_ITEMS, makeItem(R.string.mainmenu_upvoted, MainMenuFragment.MENU_MENU_ACTION_UPVOTED, rrIconUpvote, isFirst.getAndSet(false))); if (mainMenuUserItems.contains(MainMenuFragment.MainMenuUserItems.DOWNVOTED)) mAdapter.appendToGroup(GROUP_USER_ITEMS, makeItem(R.string.mainmenu_downvoted, MainMenuFragment.MENU_MENU_ACTION_DOWNVOTED, rrIconDownvote, isFirst.getAndSet(false))); if (mainMenuUserItems.contains(MainMenuFragment.MainMenuUserItems.MODMAIL)) mAdapter.appendToGroup(GROUP_USER_ITEMS, makeItem(R.string.mainmenu_modmail, MainMenuFragment.MENU_MENU_ACTION_MODMAIL, rrIconEnvOpen, isFirst.getAndSet(false))); } } setPinnedSubreddits(); if (PrefsUtility.pref_appearance_show_blocked_subreddits_main_menu(context, PreferenceManager.getDefaultSharedPreferences(context))) { setBlockedSubreddits(); } if (!user.isAnonymous()) { showMultiredditsHeader(context); final LoadingSpinnerView multiredditsLoadingSpinnerView = new LoadingSpinnerView(context); final int paddingPx = General.dpToPixels(context, 30); multiredditsLoadingSpinnerView.setPadding(paddingPx, paddingPx, paddingPx, paddingPx); final GroupedRecyclerViewItemFrameLayout multiredditsLoadingItem = new GroupedRecyclerViewItemFrameLayout( multiredditsLoadingSpinnerView); mAdapter.appendToGroup(GROUP_MULTIREDDITS_ITEMS, multiredditsLoadingItem); } mAdapter.appendToGroup(GROUP_SUBREDDITS_HEADER, new GroupedRecyclerViewItemListSectionHeaderView( context.getString(R.string.mainmenu_header_subreddits_subscribed))); { final LoadingSpinnerView subredditsLoadingSpinnerView = new LoadingSpinnerView(context); final int paddingPx = General.dpToPixels(context, 30); subredditsLoadingSpinnerView.setPadding(paddingPx, paddingPx, paddingPx, paddingPx); final GroupedRecyclerViewItemFrameLayout subredditsLoadingItem = new GroupedRecyclerViewItemFrameLayout( subredditsLoadingSpinnerView); mAdapter.appendToGroup(GROUP_SUBREDDITS_ITEMS, subredditsLoadingItem); } }
From source file:io.pravega.segmentstore.server.containers.StreamSegmentMapperTests.java
/** * Tests the ability of the StreamSegmentMapper to generate/return the Id of an existing StreamSegment, with concurrent requests. *///from w w w . j a va2s . com @Test public void testGetOrAssignStreamSegmentIdWithConcurrency() throws Exception { // We setup a delay in the OperationLog process. We only do this for a stand-alone StreamSegment because the process // is driven by the same code for Transactions as well. final String segmentName = "Segment"; final long segmentId = 12345; HashSet<String> storageSegments = new HashSet<>(); storageSegments.add(segmentName); @Cleanup TestContext context = new TestContext(); setupStorageGetHandler(context, storageSegments, sn -> new StreamSegmentInformation(sn, 0, false, false, new ImmutableDate())); CompletableFuture<Long> initialAddFuture = new CompletableFuture<>(); AtomicBoolean operationLogInvoked = new AtomicBoolean(false); context.operationLog.addHandler = op -> { if (!(op instanceof StreamSegmentMapOperation)) { return FutureHelpers.failedFuture(new IllegalArgumentException("unexpected operation")); } if (operationLogInvoked.getAndSet(true)) { return FutureHelpers.failedFuture(new IllegalStateException("multiple calls to OperationLog.add")); } // Need to set SegmentId on operation. ((StreamSegmentMapOperation) op).setStreamSegmentId(segmentId); return initialAddFuture; }; CompletableFuture<Long> firstCall = context.mapper.getOrAssignStreamSegmentId(segmentName, TIMEOUT); CompletableFuture<Long> secondCall = context.mapper.getOrAssignStreamSegmentId(segmentName, TIMEOUT); Thread.sleep(20); Assert.assertFalse("getOrAssignStreamSegmentId (first call) returned before OperationLog finished.", firstCall.isDone()); Assert.assertFalse("getOrAssignStreamSegmentId (second call) returned before OperationLog finished.", secondCall.isDone()); initialAddFuture.complete(1L); long firstCallResult = firstCall.get(100, TimeUnit.MILLISECONDS); long secondCallResult = secondCall.get(100, TimeUnit.MILLISECONDS); Assert.assertEquals( "Two concurrent calls to getOrAssignStreamSegmentId for the same StreamSegment returned different ids.", firstCallResult, secondCallResult); }
From source file:org.apache.flink.client.program.rest.RestClusterClientTest.java
/** * Tests that the send operation is being retried. *//*from w w w . j a v a 2 s . co m*/ @Test public void testRetriableSendOperationIfConnectionErrorOrServiceUnavailable() throws Exception { final PingRestHandler pingRestHandler = new PingRestHandler( FutureUtils.completedExceptionally( new RestHandlerException("test exception", HttpResponseStatus.SERVICE_UNAVAILABLE)), CompletableFuture.completedFuture(EmptyResponseBody.getInstance())); try (final TestRestServerEndpoint restServerEndpoint = createRestServerEndpoint(pingRestHandler)) { final AtomicBoolean firstPollFailed = new AtomicBoolean(); failHttpRequest = (messageHeaders, messageParameters, requestBody) -> messageHeaders instanceof PingRestHandlerHeaders && !firstPollFailed.getAndSet(true); restClusterClient.sendRequest(PingRestHandlerHeaders.INSTANCE).get(); } }
From source file:org.apache.flink.client.program.rest.RestClusterClientTest.java
@Test public void testSubmitJobAndWaitForExecutionResult() throws Exception { final TestJobExecutionResultHandler testJobExecutionResultHandler = new TestJobExecutionResultHandler( new RestHandlerException("should trigger retry", HttpResponseStatus.SERVICE_UNAVAILABLE), JobExecutionResultResponseBody.inProgress(), JobExecutionResultResponseBody.created(new JobResult.Builder() .applicationStatus(ApplicationStatus.SUCCEEDED).jobId(jobId).netRuntime(Long.MAX_VALUE) .accumulatorResults(Collections.singletonMap("testName", new SerializedValue<>(OptionalFailure.of(1.0)))) .build()),/* ww w . j av a 2 s . co m*/ JobExecutionResultResponseBody.created(new JobResult.Builder() .applicationStatus(ApplicationStatus.FAILED).jobId(jobId).netRuntime(Long.MAX_VALUE) .serializedThrowable(new SerializedThrowable(new RuntimeException("expected"))).build())); // fail first HTTP polling attempt, which should not be a problem because of the retries final AtomicBoolean firstPollFailed = new AtomicBoolean(); failHttpRequest = (messageHeaders, messageParameters, requestBody) -> messageHeaders instanceof JobExecutionResultHeaders && !firstPollFailed.getAndSet(true); try (TestRestServerEndpoint ignored = createRestServerEndpoint(testJobExecutionResultHandler, new TestJobSubmitHandler())) { JobExecutionResult jobExecutionResult; jobExecutionResult = (JobExecutionResult) restClusterClient.submitJob(jobGraph, ClassLoader.getSystemClassLoader()); assertThat(jobExecutionResult.getJobID(), equalTo(jobId)); assertThat(jobExecutionResult.getNetRuntime(), equalTo(Long.MAX_VALUE)); assertThat(jobExecutionResult.getAllAccumulatorResults(), equalTo(Collections.singletonMap("testName", 1.0))); try { restClusterClient.submitJob(jobGraph, ClassLoader.getSystemClassLoader()); fail("Expected exception not thrown."); } catch (final ProgramInvocationException e) { final Optional<RuntimeException> cause = ExceptionUtils.findThrowable(e, RuntimeException.class); assertThat(cause.isPresent(), is(true)); assertThat(cause.get().getMessage(), equalTo("expected")); } } }
From source file:edu.umn.msi.tropix.common.jobqueue.test.IntegrationTestBase.java
protected boolean pollJob(final Job job, final JobQueueContext context) { final CountDownLatch completeLatch = new CountDownLatch(1), postprocessLatch = new CountDownLatch(1); final AtomicBoolean previouslyLaunchedFileTransfer = new AtomicBoolean(false); class Listener implements JobUpdateListener { private boolean finishedProperly = false; public void jobComplete(final Ticket ticket, final boolean finishedProperly, final Status finalStatus) { this.finishedProperly = finishedProperly; completeLatch.countDown();/*from w ww .j av a2 s. c o m*/ } public void update(final Ticket ticket, final Status status) { final QueueStage stage = QueueStage.fromStatusUpdateList(status); LOG.info("Queue stage is [" + stage.getStageEnumerationValue().getValue() + "]"); if (stage.getStageEnumerationValue() == StageEnumeration.Postprocessed && startTransfer()) { postprocessLatch.countDown(); } } private boolean startTransfer() { final boolean wasFalse = previouslyLaunchedFileTransfer.getAndSet(true); return !wasFalse; } } final Listener listener = new Listener(); dListener.setJobUpdateListener(listener); jobPoller.pollJob(job); postprocessLatch.await(); final FileJobQueueContext fileContext = (FileJobQueueContext) context; final int numResults = fileContext.getNumResults(); final TransferResource[] results = new TransferResource[numResults]; for (int i = 0; i < numResults; i++) { final StorageData storageData = getStorageData(); getResults().add(storageData); results[i] = storageData.prepareUploadResource(); } fileContext.getResults(results, null); completeLatch.await(); jobCompletedProperly = listener.finishedProperly; return jobCompletedProperly; }
From source file:org.apache.flink.client.program.rest.RestClusterClientTest.java
@Test public void testTriggerSavepoint() throws Exception { final String targetSavepointDirectory = "/tmp"; final String savepointLocationDefaultDir = "/other/savepoint-0d2fb9-8d5e0106041a"; final String savepointLocationRequestedDir = targetSavepointDirectory + "/savepoint-0d2fb9-8d5e0106041a"; final TestSavepointHandlers testSavepointHandlers = new TestSavepointHandlers(); final TestSavepointHandlers.TestSavepointTriggerHandler triggerHandler = testSavepointHandlers.new TestSavepointTriggerHandler( null, targetSavepointDirectory, null, null); final TestSavepointHandlers.TestSavepointHandler savepointHandler = testSavepointHandlers.new TestSavepointHandler( new SavepointInfo(savepointLocationDefaultDir, null), new SavepointInfo(savepointLocationRequestedDir, null), new SavepointInfo(null, new SerializedThrowable(new RuntimeException("expected"))), new RestHandlerException("not found", HttpResponseStatus.NOT_FOUND)); // fail first HTTP polling attempt, which should not be a problem because of the retries final AtomicBoolean firstPollFailed = new AtomicBoolean(); failHttpRequest = (messageHeaders, messageParameters, requestBody) -> messageHeaders instanceof SavepointStatusHeaders && !firstPollFailed.getAndSet(true); try (TestRestServerEndpoint ignored = createRestServerEndpoint(triggerHandler, savepointHandler)) { JobID id = new JobID(); {/*from ww w . j a v a2s .co m*/ CompletableFuture<String> savepointPathFuture = restClusterClient.triggerSavepoint(id, null); String savepointPath = savepointPathFuture.get(); assertEquals(savepointLocationDefaultDir, savepointPath); } { CompletableFuture<String> savepointPathFuture = restClusterClient.triggerSavepoint(id, targetSavepointDirectory); String savepointPath = savepointPathFuture.get(); assertEquals(savepointLocationRequestedDir, savepointPath); } { try { restClusterClient.triggerSavepoint(id, null).get(); fail("Expected exception not thrown."); } catch (ExecutionException e) { final Throwable cause = e.getCause(); assertThat(cause, instanceOf(SerializedThrowable.class)); assertThat(((SerializedThrowable) cause).deserializeError(ClassLoader.getSystemClassLoader()) .getMessage(), equalTo("expected")); } } try { restClusterClient.triggerSavepoint(new JobID(), null).get(); fail("Expected exception not thrown."); } catch (final ExecutionException e) { assertTrue("RestClientException not in causal chain", ExceptionUtils.findThrowable(e, RestClientException.class).isPresent()); } } }