Skip to content
Open
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,5 @@ For the most cases it's recommended to use these database specific starters:
* [dbaas-client-cassandra-starter](./dbaas-client-java/dbaas-client-cassandra-starter/README.md)
* [dbaas-client-opensearch-starter](./dbaas-client-java/dbaas-client-opensearch-starter/README.md)
* [dbaas-client-cassandra-starter](./dbaas-client-java/dbaas-client-cassandra-starter/README.md)


Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

@Slf4j
public class CassandraTestContainer extends CassandraContainer<CassandraTestContainer> {
private static final String IMAGE_VERSION = "cassandra:latest";
private static final String IMAGE_VERSION = "cassandra:4.1";
private static CassandraTestContainer container;

private CassandraTestContainer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

@Slf4j
public class CassandraTestContainer extends CassandraContainer<CassandraTestContainer> {
private static final String IMAGE_VERSION = "cassandra:latest";
private static final String IMAGE_VERSION = "cassandra:4.1";
private static CassandraTestContainer container;

private CassandraTestContainer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

@Slf4j
public class CassandraTestContainer extends CassandraContainer<CassandraTestContainer> {
private static final String IMAGE_VERSION = "cassandra:latest";
private static final String IMAGE_VERSION = "cassandra:4.1";
private static CassandraTestContainer container;

private CassandraTestContainer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public static MongoTestContainer getInstance() {
.withEnv("MONGO_INITDB_ROOT_PASSWORD", MONGO_ADMIN_PWD)
.withEnv("MONGO_INITDB_DATABASE", MONGO_ADMIN_DB)
.withExposedPorts(MONGO_PORT)
.withStartupTimeout(Duration.ofSeconds(120));
.withStartupTimeout(Duration.ofSeconds(120))
.withReuse(true);
}
return container;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public static MongoWithTransactionsTestContainer getInstance() {
container = (MongoWithTransactionsTestContainer) new MongoWithTransactionsTestContainer()
.withEnv("MONGO_INITDB_DATABASE", MONGO_ADMIN_DB)
.withExposedPorts(MONGO_PORT)
.withStartupTimeout(Duration.ofSeconds(120));
.withStartupTimeout(Duration.ofSeconds(120))
.withReuse(true);
}
return container;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
testcontainers.reuse.enable=true
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,14 @@
import org.springframework.test.context.web.WebAppConfiguration;

import java.io.IOException;
import java.time.Duration;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;

import static org.awaitility.Awaitility.await;

import static com.netcracker.cloud.dbaas.client.opensearch.restclient.configuration.OpensearchTestConfiguration.TEST_INDEX;
import static com.netcracker.cloud.dbaas.client.opensearch.restclient.configuration.OpensearchTestConfiguration.TEST_PREFIX;
Expand All @@ -69,8 +73,6 @@
@Slf4j
class DbaasOpensearchClientImplTest {

private static int SECOND = 1000;

@Autowired
private OpensearchProperties opensearchProperties;

Expand Down Expand Up @@ -206,31 +208,36 @@ void bulk() throws IOException {
}

@Test
void reindex() throws IOException, InterruptedException {
void reindex() throws IOException {
String destinationIndex = "dest_reindex";
upsertDocument("1", "get", "get value");
Thread.sleep(SECOND);
ReindexRequest reindexRequest = new ReindexRequest.Builder()
.source(new Source.Builder().index(serviceClient.normalize(TEST_INDEX)).build())
.dest(new Destination.Builder().index(serviceClient.normalize(destinationIndex)).build())
.refresh(Refresh.True)
.build();
ReindexResponse reindexResponse = serviceClient.getClient().reindex(reindexRequest);
assertNotNull(reindexResponse);
Thread.sleep(5L * SECOND);
assertEquals(Long.valueOf(1L), reindexResponse.created());

GetRequest getRequest = new GetRequest.Builder().index(serviceClient.normalize(destinationIndex)).id("1").build();
GetResponse getResponse = serviceClient.getClient().get(getRequest, Map.class);
assertTrue(getResponse.found());
await().atMost(Duration.ofSeconds(5))
.pollInterval(Duration.ofMillis(200))
.untilAsserted(() -> {
GetResponse response = serviceClient.getClient().get(getRequest, Map.class);
assertTrue(response.found());
});

deleteIndex(destinationIndex);
}

@Test
void updateByQueryOneIndex() throws IOException, InterruptedException {
void updateByQueryOneIndex() throws IOException {
upsertDocument("1", "User", "Kimchy");
Thread.sleep(SECOND);
UpdateByQueryRequest request = new UpdateByQueryRequest.Builder().index(serviceClient.normalize(TEST_INDEX))
.query(new Query.Builder().matchAll(new MatchAllQuery.Builder().build()).build())
.script(new Script.Builder().inline(new InlineScript.Builder().source("ctx._source.Field=3;").build()).build())
.refresh(Refresh.True)
.build();
UpdateByQueryResponse bulkResponse = serviceClient.getClient().updateByQuery(request);
assertNotNull(bulkResponse);
Expand All @@ -243,14 +250,14 @@ void updateByQueryOneIndex() throws IOException, InterruptedException {
}

@Test
void updateByQueryManyIndex() throws IOException, InterruptedException {
void updateByQueryManyIndex() throws IOException {
upsertDocument("1", "one", "first doc");
upsertDocument("1", "one", "another docs", secondIndexName);
Thread.sleep(SECOND);
UpdateByQueryRequest request = new UpdateByQueryRequest.Builder()
.index(serviceClient.normalize(TEST_INDEX), serviceClient.normalize(secondIndexName))
.query(new Query.Builder().matchAll(new MatchAllQuery.Builder().build()).build())
.script(new Script.Builder().inline(new InlineScript.Builder().source("ctx._source.Field=3;").build()).build())
.refresh(Refresh.True)
.build();
UpdateByQueryResponse bulkResponse = serviceClient.getClient().updateByQuery(request);
assertNotNull(bulkResponse);
Expand All @@ -268,14 +275,14 @@ void updateByQueryManyIndex() throws IOException, InterruptedException {
}

@Test
void deleteByQueryFromManyIndex() throws IOException, InterruptedException {
void deleteByQueryFromManyIndex() throws IOException {
upsertDocument("1", "User", "Kimchy");
upsertDocument("1", "User", "Twitter", secondIndexName);
Thread.sleep(SECOND);

DeleteByQueryRequest request = new DeleteByQueryRequest.Builder()
.index(serviceClient.normalize(TEST_INDEX), serviceClient.normalize(secondIndexName))
.query(new Query.Builder().matchAll(new MatchAllQuery.Builder().build()).build())
.refresh(Refresh.True)
.build();
DeleteByQueryResponse bulkResponse = serviceClient.getClient().deleteByQuery(request);
assertNotNull(bulkResponse);
Expand Down Expand Up @@ -395,19 +402,17 @@ void index() throws IOException {
}

@Test
void count() throws IOException, InterruptedException {
void count() throws IOException {
upsertDocument("1", "count", "count value");
upsertDocument("2", "count", "another count value", secondIndexName);
Thread.sleep(SECOND);
CountRequest countRequest = new CountRequest.Builder().index(serviceClient.normalize(TEST_INDEX), serviceClient.normalize(secondIndexName)).build();
CountResponse countResponse = serviceClient.getClient().count(countRequest);
assertEquals(2, countResponse.count());
}

@Test
void update() throws IOException, InterruptedException {
void update() throws IOException {
upsertDocument("1", "update", "update value");
Thread.sleep(SECOND);
GetRequest getRequestBeforeUpdate = new GetRequest.Builder().index(serviceClient.normalize(TEST_INDEX)).id("1").build();
GetResponse<Map> firstGetResponse = serviceClient.getClient().get(getRequestBeforeUpdate, Map.class);
assertEquals(1, firstGetResponse.version());
Expand Down Expand Up @@ -444,9 +449,8 @@ void deleteNotFound() throws IOException {
}

@Test
void search() throws IOException, InterruptedException {
void search() throws IOException {
upsertDocument("1", "search", "value-search");
Thread.sleep(SECOND);
SearchRequest searchRequest = new SearchRequest.Builder()
.index(serviceClient.normalize(TEST_INDEX))
.query(new Query.Builder().matchAll(new MatchAllQuery.Builder().build()).build())
Expand All @@ -462,10 +466,9 @@ void search() throws IOException, InterruptedException {
}

@Test
void msearch() throws IOException, InterruptedException {
void msearch() throws IOException {
upsertDocument("1", "FirstKey", "FirstValue");
upsertDocument("1", "SecondKey", "SecondValue", secondIndexName);
Thread.sleep(SECOND);

MsearchRequest request = new MsearchRequest.Builder()
.searches(
Expand Down Expand Up @@ -540,10 +543,9 @@ void clearScroll() throws IOException {
}

@Test
void searchTemplate() throws IOException, InterruptedException {
void searchTemplate() throws IOException {
upsertDocument("1", "Key", "Value");
upsertDocument("2", "Key", "Value", secondIndexName);
Thread.sleep(SECOND);

Map<String, JsonData> scriptParams = new HashMap<>();
scriptParams.put("field", JsonData.of("Key"));
Expand All @@ -566,9 +568,8 @@ void searchTemplate() throws IOException, InterruptedException {
}

@Test
void explain() throws IOException, InterruptedException {
void explain() throws IOException {
upsertDocument("1", "Key", "Value");
Thread.sleep(SECOND);
ExplainRequest request = new ExplainRequest.Builder()
.index(serviceClient.normalize(TEST_INDEX))
.id("1")
Expand All @@ -581,9 +582,8 @@ void explain() throws IOException, InterruptedException {
}

@Test
void termvectors() throws IOException, InterruptedException {
void termvectors() throws IOException {
upsertDocument("1", "Key", "Value");
Thread.sleep(SECOND);
TermvectorsRequest<Map> request = new TermvectorsRequest.Builder<Map>()
.index(serviceClient.normalize(TEST_INDEX))
.id("1")
Expand All @@ -594,9 +594,8 @@ void termvectors() throws IOException, InterruptedException {
}

@Test
void rankEval() throws IOException, InterruptedException {
void rankEval() throws IOException {
upsertDocument("1", "user", "kimchy");
Thread.sleep(SECOND);
RankEvalRequest request = new RankEvalRequest.Builder()
.index(serviceClient.normalize(TEST_INDEX))
.metric(new RankEvalMetric.Builder()
Expand Down Expand Up @@ -664,10 +663,9 @@ void msearchTemplate() throws IOException {

@Test
@Disabled("https://github.com/opensearch-project/opensearch-java/issues/1792")
void fieldCaps() throws IOException, InterruptedException {
void fieldCaps() throws IOException {
upsertDocument("1", "Key", "Val");
upsertDocument("1", "Key", "Val", secondIndexName);
Thread.sleep(SECOND);
FieldCapsRequest request = new FieldCapsRequest.Builder()
.index(serviceClient.normalize(TEST_INDEX), serviceClient.normalize(secondIndexName))
.fields("Key")
Expand All @@ -690,6 +688,7 @@ private void upsertDocument(String id, String key, String value, String indexNam
.index(serviceClient.normalize(indexName))
.id(id)
.document(Map.of(key, value))
.refresh(Refresh.True)
.build();
serviceClient.getClient().index(updateIndexRequest);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public static OpensearchTestContainer getInstance() {
.withEnv("DISABLE_SECURITY_PLUGIN", "true")
.withEnv("DISABLE_INSTALL_DEMO_CONFIG", "true")
.withEnv("discovery.type", "single-node")
.withStartupTimeout(Duration.ofSeconds(120));
.withStartupTimeout(Duration.ofSeconds(120))
.withReuse(true);
}
return opensearchContainer;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
testcontainers.reuse.enable=true
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

@Slf4j
public class CassandraTestContainer extends CassandraContainer<CassandraTestContainer> {
private static final String IMAGE_VERSION = "cassandra:3";
private static final String IMAGE_VERSION = "cassandra:4.1";
private static CassandraTestContainer container;

private CassandraTestContainer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public static MongoTestContainer getInstance() {
.withEnv("MONGO_INITDB_ROOT_PASSWORD", MONGO_ADMIN_PWD)
.withEnv("MONGO_INITDB_DATABASE", MONGO_ADMIN_DB)
.withExposedPorts(MONGO_PORT)
.withStartupTimeout(Duration.ofSeconds(120));
.withStartupTimeout(Duration.ofSeconds(120))
.withReuse(true);
}
return container;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
testcontainers.reuse.enable=true
Loading