Skip to content

Commit

Permalink
Test releasing lock to avoid any query cache issues
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Widdis <[email protected]>
  • Loading branch information
dbwiddis committed Jul 10, 2023
1 parent 5d3bfe5 commit d802e1c
Showing 1 changed file with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@

import java.io.IOException;

import org.apache.hc.core5.http.HttpEntity;
import org.junit.Before;
import org.opensearch.client.Response;
import org.opensearch.client.ResponseException;
import org.opensearch.common.xcontent.LoggingDeprecationHandler;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.xcontent.NamedXContentRegistry;
Expand All @@ -25,7 +23,7 @@

import com.google.common.collect.ImmutableMap;

@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.SUITE, numDataNodes = 2)
@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST, numDataNodes = 21)
public class GetLockMultiNodeRestIT extends ODFERestTestCase {

private String initialJobId;
Expand Down Expand Up @@ -55,26 +53,30 @@ public void testGetLockRestAPI() throws Exception {
assertEquals(TestHelpers.generateExpectedLockId(initialJobIndexName, initialJobId), initialLockId);

// Submit 10 requests to generate new lock models for different job indexes
for (int i = 0; i < 10; i++) {
final HttpEntity httpEntity = TestHelpers.toHttpEntity(
TestHelpers.generateAcquireLockRequestBody(String.valueOf(i), String.valueOf(i))
);
for (int i = 0; i < 10000; i++) {
String expectedLockId = TestHelpers.generateExpectedLockId(String.valueOf(i), String.valueOf(i));
Response getLockResponse = TestHelpers.makeRequest(
client(),
"GET",
TestHelpers.GET_LOCK_BASE_URI,
ImmutableMap.of(),
httpEntity,
TestHelpers.toHttpEntity(TestHelpers.generateAcquireLockRequestBody(String.valueOf(i), String.valueOf(i))),
null
);
// Releasing lock will test that it exists (Get by ID)
Response releaseLockResponse = TestHelpers.makeRequest(
client(),
"PUT",
TestHelpers.RELEASE_LOCK_BASE_URI + "/" + expectedLockId,
ImmutableMap.of(),
null,
null
);
// attempt to acquire same lock should fail
assertThrows(ResponseException.class, () -> {
TestHelpers.makeRequest(client(), "GET", TestHelpers.GET_LOCK_BASE_URI, ImmutableMap.of(), httpEntity, null);
});
assertEquals("success", entityAsMap(releaseLockResponse).get("release-lock"));

String lockId = validateResponseAndGetLockId(getLockResponse);

assertEquals(TestHelpers.generateExpectedLockId(String.valueOf(i), String.valueOf(i)), lockId);
assertEquals(expectedLockId, lockId);
}
}

Expand Down

0 comments on commit d802e1c

Please sign in to comment.