Skip to content

Commit 2fe47dc

Browse files
committed
Run test
1 parent bdda228 commit 2fe47dc

File tree

5 files changed

+132
-84
lines changed

5 files changed

+132
-84
lines changed

.github/workflows/test-astra-dev.yml

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
run: |
2323
mvn install -Dmaven.test.skip=true
2424
25-
AWS_US_WEST2:
25+
AWS_US_WEST2_CORE:
2626
needs: BUILD
2727
runs-on: ubuntu-latest
2828
steps:
@@ -62,8 +62,28 @@ jobs:
6262
cd astra-db-java
6363
mvn test -Dtest=com.datastax.astra.test.integration.dev.*Test
6464
65-
GCP_US_CENTRAL1:
66-
needs: BUILD
65+
# GCP_US_CENTRAL1:
66+
# needs: BUILD
67+
# runs-on: ubuntu-latest
68+
# steps:
69+
# - name: Checkout repository
70+
# uses: actions/checkout@v2
71+
# - name: Set up JDK
72+
# uses: actions/setup-java@v2
73+
# with:
74+
# distribution: 'adopt'
75+
# java-version: 11
76+
#
77+
# - name: Run test for DEV
78+
# env:
79+
# ASTRA_DB_APPLICATION_TOKEN_DEV: ${{ secrets.ASTRA_DB_APPLICATION_TOKEN_DEV }}
80+
# ASTRA_CLOUD_PROVIDER_DEV: GCP
81+
# ASTRA_CLOUD_REGION_DEV: us-central1
82+
# run: |
83+
# cd astra-db-java
84+
# mvn test -Dtest=com.datastax.astra.test.integration.dev.*Test
85+
AWS_US_WEST2_OPEN_AI:
86+
needs: AWS_US_WEST2_CORE
6787
runs-on: ubuntu-latest
6888
steps:
6989
- name: Checkout repository
@@ -73,12 +93,35 @@ jobs:
7393
with:
7494
distribution: 'adopt'
7595
java-version: 11
96+
- name: Maven Test
97+
env:
98+
ASTRA_DB_APPLICATION_TOKEN_DEV: ${{ secrets.ASTRA_DB_APPLICATION_TOKEN_DEV }}
99+
ASTRA_CLOUD_PROVIDER_DEV: AWS
100+
ASTRA_CLOUD_REGION_DEV: us-west-2
101+
EMBEDDING_PROVIDER: openai
102+
EMBEDDING_API_KEY: ${{ secrets.OPENAI_API_KEY }}
103+
run: |
104+
cd astra-db-java
105+
mvn test -Dtest=com.datastax.astra.test.integration.dev_vectorize.AstraDevVectorizeEmbeddingApiKeyITTest
76106
77-
- name: Run test for DEV
107+
AWS_US_WEST2_AZURE_OPEN_AI:
108+
needs: AWS_US_WEST2_CORE
109+
runs-on: ubuntu-latest
110+
steps:
111+
- name: Checkout repository
112+
uses: actions/checkout@v2
113+
- name: Set up JDK
114+
uses: actions/setup-java@v2
115+
with:
116+
distribution: 'adopt'
117+
java-version: 11
118+
- name: Maven Test
78119
env:
79120
ASTRA_DB_APPLICATION_TOKEN_DEV: ${{ secrets.ASTRA_DB_APPLICATION_TOKEN_DEV }}
80-
ASTRA_CLOUD_PROVIDER_DEV: GCP
81-
ASTRA_CLOUD_REGION_DEV: us-central1
121+
ASTRA_CLOUD_PROVIDER_DEV: AWS
122+
ASTRA_CLOUD_REGION_DEV: us-west-2
123+
EMBEDDING_PROVIDER: azureOpenAI
124+
EMBEDDING_API_KEY: ${{ secrets.AZURE_OPENAI_API_KEY }}
82125
run: |
83126
cd astra-db-java
84-
mvn test -Dtest=com.datastax.astra.test.integration.dev.*Test
127+
mvn test -Dtest=com.datastax.astra.test.integration.dev_vectorize.AstraDevVectorizeEmbeddingApiKeyITTest

astra-db-java/src/main/java/com/datastax/astra/client/admin/AstraDBAdmin.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
@Slf4j
5353
public class AstraDBAdmin {
5454

55+
public static final Integer WAIT_IN_SECONDS = 600;
56+
5557
/** Default cloud provider. (free-tier) */
5658
public static final CloudProviderType FREE_TIER_CLOUD = CloudProviderType.GCP;
5759

@@ -370,17 +372,17 @@ public AstraDBDatabaseAdmin getDatabaseAdmin(UUID databaseId) {
370372
@SuppressWarnings("java:S2925")
371373
private void waitForDatabase(DbOpsClient dbc) {
372374
long top = System.currentTimeMillis();
373-
while(DatabaseStatusType.ACTIVE != getStatus(dbc) && ((System.currentTimeMillis()-top) < 1000L*180)) {
375+
while(DatabaseStatusType.ACTIVE != getStatus(dbc) && ((System.currentTimeMillis()-top) < 1000L*WAIT_IN_SECONDS)) {
374376
try {
375377
Thread.sleep( 5000);
376-
log.info("");
378+
log.info("...waiting for database '" + dbc.get().getInfo().getName() + "' to become active...");
377379
} catch (InterruptedException e) {
378380
log.warn("Interrupted {}",e.getMessage());
379381
Thread.currentThread().interrupt();
380382
}
381383
}
382384
if (getStatus(dbc) != DatabaseStatusType.ACTIVE) {
383-
throw new IllegalStateException("Database is not in expected state after timeouts");
385+
throw new IllegalStateException("Database is not in expected state after timeouts of " + WAIT_IN_SECONDS + " seconds.");
384386
}
385387
}
386388

astra-db-java/src/test/java/com/datastax/astra/test/integration/AbstractVectorizeITTest.java

Lines changed: 31 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -35,66 +35,7 @@
3535

3636
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
3737
@Slf4j
38-
public abstract class AbstractVectorizeITTest {
39-
40-
/**
41-
* Reference to working DataApiNamespace
42-
*/
43-
protected static Database database;
44-
45-
/**
46-
* Initialization of the DataApiNamespace.
47-
*
48-
* @return
49-
* the instance of Data ApiNamespace
50-
*/
51-
protected abstract Database initDatabase();
52-
53-
/**
54-
* Initialize the Test database on an Astra Environment.
55-
*
56-
* @param env
57-
* target environment
58-
* @param cloud
59-
* target cloud
60-
* @param region
61-
* target region
62-
* @return
63-
* the database instance
64-
*/
65-
public static Database initAstraDatabase(AstraEnvironment env, String dbName, CloudProviderType cloud, String region) {
66-
log.info("Working in environment '{}'", env.name());
67-
AstraDBAdmin client = getAstraDBClient(env);
68-
DatabaseAdmin databaseAdmin = client.createDatabase(dbName, cloud, region);
69-
return databaseAdmin.getDatabase();
70-
}
71-
72-
/**
73-
* Access AstraDBAdmin for different environment (to create DB).
74-
*
75-
* @param env
76-
* astra environment
77-
* @return
78-
* instance of AstraDBAdmin
79-
*/
80-
public static AstraDBAdmin getAstraDBClient(AstraEnvironment env) {
81-
switch (env) {
82-
case DEV:
83-
return DataAPIClients.createForAstraDev(Utils.readEnvVariable("ASTRA_DB_APPLICATION_TOKEN_DEV")
84-
.orElseThrow(() -> new IllegalStateException("Please define env variable 'ASTRA_DB_APPLICATION_TOKEN_DEV'")))
85-
.getAdmin();
86-
case PROD:
87-
return DataAPIClients.create(Utils.readEnvVariable("ASTRA_DB_APPLICATION_TOKEN")
88-
.orElseThrow(() -> new IllegalStateException("Please define env variable 'ASTRA_DB_APPLICATION_TOKEN'")))
89-
.getAdmin();
90-
case TEST:
91-
return DataAPIClients.createForAstraTest(Utils.readEnvVariable("ASTRA_DB_APPLICATION_TOKEN_TEST")
92-
.orElseThrow(() -> new IllegalStateException("Please define env variable 'ASTRA_DB_APPLICATION_TOKEN_TEST'")))
93-
.getAdmin();
94-
default:
95-
throw new IllegalArgumentException("Invalid Environment");
96-
}
97-
}
38+
public abstract class AbstractVectorizeITTest extends AbstractDataAPITest {
9839

9940
public static String getApiKey(String provider) {
10041
if (provider.equals("openai")) {
@@ -129,19 +70,6 @@ public Map<String, Object> getParameters(String provider) {
12970
return null;
13071
}
13172

132-
/**
133-
* Initialization of the working Namespace.
134-
*
135-
* @return
136-
* current Namespace
137-
*/
138-
protected Database getDatabase() {
139-
if (database == null) {
140-
database = initDatabase();
141-
}
142-
return database;
143-
}
144-
14573
protected void dropCollection(String name) {
14674
getDatabase().dropCollection(name);
14775
log.info("Collection {} dropped", name);
@@ -312,6 +240,18 @@ public void shouldTestOneProvider(String provider) {
312240
}
313241
}
314242

243+
public void shouldTestOneProvider(String provider, String embeddingApiKey) {
244+
for (Map.Entry<String, EmbeddingProvider> entry : getDatabase()
245+
.getDatabaseAdmin()
246+
.findEmbeddingProviders()
247+
.getEmbeddingProviders()
248+
.entrySet()) {
249+
if (entry.getKey().equals(provider)) {
250+
this.testEmbeddingProvider(entry.getKey(), entry.getValue(), embeddingApiKey);
251+
}
252+
}
253+
}
254+
315255
public void shouldTestOneProviderSharedKey(String provider, String keyName) {
316256
for (Map.Entry<String, EmbeddingProvider> entry : getDatabase()
317257
.getDatabaseAdmin()
@@ -324,4 +264,22 @@ public void shouldTestOneProviderSharedKey(String provider, String keyName) {
324264
}
325265
}
326266

267+
public void testEmbeddingProvider(String key, EmbeddingProvider provider, String apiKey) {
268+
System.out.println("TESTING PROVIDER [" + key + "]");
269+
Map<String, Object> params = getParameters(key);
270+
provider.getModels().forEach(model -> {
271+
System.out.println("Processing MODEL " + model.getName());
272+
try {
273+
log.info("Testing model {}", model);
274+
Collection<Document> collection = createCollectionHeader(key, model, apiKey, params);
275+
log.info("Collection created {}", collection.getName());
276+
testCollection(collection, new EmbeddingAPIKeyHeaderProvider(apiKey));
277+
collection.drop();
278+
279+
} catch(Exception e) {
280+
log.error("Error while testing model {}", model, e);
281+
}
282+
});
283+
}
284+
327285
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.datastax.astra.test.integration.dev_vectorize;
2+
3+
import com.datastax.astra.test.integration.AbstractVectorizeITTest;
4+
import com.dtsx.astra.sdk.db.domain.CloudProviderType;
5+
import com.dtsx.astra.sdk.utils.AstraEnvironment;
6+
import lombok.extern.slf4j.Slf4j;
7+
import org.junit.jupiter.api.Disabled;
8+
import org.junit.jupiter.api.Test;
9+
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
10+
11+
import static org.assertj.core.api.Assertions.assertThat;
12+
13+
/**
14+
* Testing Vectorize in DEV
15+
*/
16+
@Disabled
17+
@Slf4j
18+
@EnabledIfEnvironmentVariable(named = "ASTRA_DB_APPLICATION_TOKEN_DEV", matches = "Astra.*")
19+
@EnabledIfEnvironmentVariable(named = "ASTRA_CLOUD_PROVIDER_DEV", matches = ".*")
20+
@EnabledIfEnvironmentVariable(named = "ASTRA_CLOUD_REGION_DEV", matches = ".*")
21+
@EnabledIfEnvironmentVariable(named = "EMBEDDING_PROVIDER", matches = ".*")
22+
@EnabledIfEnvironmentVariable(named = "EMBEDDING_API_KEY", matches = ".*")
23+
public class AstraDevVectorizeEmbeddingApiKeyITTest extends AbstractVectorizeITTest {
24+
25+
@Override
26+
public AstraEnvironment getAstraEnvironment() {
27+
return AstraEnvironment.DEV;
28+
}
29+
30+
@Override
31+
public CloudProviderType getCloudProvider() {
32+
return CloudProviderType.valueOf(System.getenv("ASTRA_CLOUD_PROVIDER_DEV"));
33+
}
34+
35+
@Override
36+
public String getRegion() {
37+
return System.getenv("ASTRA_CLOUD_REGION_DEV");
38+
}
39+
40+
@Test
41+
public void testOneProvider() {
42+
shouldTestOneProvider(System.getenv("EMBEDDING_PROVIDER"), System.getenv("EMBEDDING_API_KEY"));
43+
}
44+
45+
}

astra-db-java/src/test/java/com/datastax/astra/test/integration/dev/AstraDevVectorizeITTest.java renamed to astra-db-java/src/test/java/com/datastax/astra/test/integration/dev_vectorize/AstraDevVectorizeITTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.datastax.astra.test.integration.dev;
1+
package com.datastax.astra.test.integration.dev_vectorize;
22

33
import com.datastax.astra.client.Collection;
44
import com.datastax.astra.client.DataAPIClient;

0 commit comments

Comments
 (0)