Skip to content

Commit

Permalink
Call listner.onFailure when lock creation failed (#435) (#443)
Browse files Browse the repository at this point in the history
Signed-off-by: Heemin Kim <[email protected]>
(cherry picked from commit d2e0ac0)

Co-authored-by: Heemin Kim <[email protected]>
  • Loading branch information
opensearch-trigger-bot[bot] and heemin32 authored Aug 1, 2023
1 parent 3400c4b commit f26659b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -236,17 +236,16 @@ private void createLock(final LockModel tempLock, ActionListener<LockModel> list
exception -> {
if (exception instanceof VersionConflictEngineException) {
logger.debug("Lock is already created. {}", exception.getMessage());
listener.onResponse(null);
return;
}
if (exception instanceof IOException) {
logger.error("IOException occurred creating lock", exception);
}
listener.onResponse(null);
listener.onFailure(exception);
}
)
);
} catch (IOException e) {
logger.error("IOException occurred creating lock", e);
listener.onResponse(null);
listener.onFailure(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,28 @@ public void testSecondAcquireLockFail() throws Exception {
latch.await(10L, TimeUnit.SECONDS);
}

public void testAcquireLockWithLongIdFail() throws Exception {
String uniqSuffix = "_long_lock_id";
String lockID = randomAlphaOfLengthBetween(513, 1000);
CountDownLatch latch = new CountDownLatch(1);
LockService lockService = new LockService(client(), this.clusterService);
final JobExecutionContext context = new JobExecutionContext(
Instant.now(),
new JobDocVersion(0, 0, 0),
lockService,
JOB_INDEX_NAME + uniqSuffix,
JOB_ID + uniqSuffix
);

lockService.acquireLockWithId(context.getJobIndexName(), LOCK_DURATION_SECONDS, lockID, ActionListener.wrap(lock -> {
fail("should throw an exception");
}, exception -> {
assertTrue(exception.getMessage().contains("too long"));
latch.countDown();
}));
latch.await(10L, TimeUnit.SECONDS);
}

public void testLockReleasedAndAcquired() throws Exception {
String uniqSuffix = "_lock_release+acquire";
String lockID = randomAlphaOfLengthBetween(6, 15);
Expand Down

0 comments on commit f26659b

Please sign in to comment.