Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call listner.onFailure when lock creation failed #435

Merged
merged 1 commit into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading