Skip to content

Commit 8fa5104

Browse files
committed
fixing tests
1 parent 619359d commit 8fa5104

File tree

18 files changed

+159
-112
lines changed

18 files changed

+159
-112
lines changed

astra-db-java/src/main/java/com/datastax/astra/client/DataAPIClient.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@
7070
*/
7171
public class DataAPIClient {
7272

73-
74-
7573
/**
7674
* The authentication token used as credentials in HTTP requests, specifically as the Authorization bearer token.
7775
* This token is crucial for accessing and interacting with Astra environments, where it plays a role in determining
@@ -303,6 +301,24 @@ public Database getDatabase(UUID databaseId, String region, DatabaseOptions dbOp
303301
return getDatabase(lookupEndpoint(databaseId, region), dbOptions);
304302
}
305303

304+
/**
305+
* Gets token
306+
*
307+
* @return value of token
308+
*/
309+
public String getToken() {
310+
return token;
311+
}
312+
313+
/**
314+
* Gets options
315+
*
316+
* @return value of options
317+
*/
318+
public DataAPIClientOptions getOptions() {
319+
return options;
320+
}
321+
306322
/**
307323
* Compute the endpoint for the database based on its ID and region.
308324
* @param databaseId

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,9 @@ public void dropKeyspace(String keyspace) {
207207
}
208208

209209
@Override
210-
public void dropKeyspace(String namespace, BaseOptions<?> options) {
210+
public void dropKeyspace(String keyspace, BaseOptions<?> options) {
211211
log.warn("CommandOptions are not supported for dropKeyspace in Astra MODE");
212-
dropKeyspace(namespace);
212+
dropKeyspace(keyspace);
213213
}
214214

215215
/** {@inheritDoc} */

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public class DataAPIDatabaseAdmin extends AbstractCommandRunner<AdminOptions> im
6868
*/
6969
public DataAPIDatabaseAdmin(Database db, AdminOptions options) {
7070
super(db.getRootEndpoint(), options);
71+
this.db = db;
7172
this.options.commandType(CommandType.KEYSPACE_ADMIN);
7273
String apiVersion = options.getDataAPIClientOptions().getApiVersion();
7374
if (!db.getRootEndpoint().endsWith(apiVersion)) {

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.datastax.astra.client.core.commands.CommandRunner;
2626
import com.datastax.astra.client.core.vectorize.EmbeddingProvider;
2727
import com.datastax.astra.client.core.results.FindEmbeddingProvidersResult;
28+
import com.datastax.astra.internal.utils.Assert;
2829

2930
import java.util.Set;
3031
import java.util.concurrent.CompletableFuture;
@@ -188,26 +189,27 @@ default CompletableFuture<Set<String>> listKeyspacesNamesAsync() {
188189
* // Assume 'client' is an instance of your data API client
189190
* String keyspace = "targetKeyspace";
190191
*
191-
* // Drop the namespace
192+
* // Drop the keyspace
192193
* client.dropKeyspace(keyspace);
193194
*
194-
* // The namespace 'targetKeyspace' is now deleted, along with all its contained data
195+
* // The keyspace 'targetKeyspace' is now deleted, along with all its contained data
195196
* }
196197
* </pre>
197198
*
198199
* This example demonstrates how to safely drop a keyspace by name. The operation ensures that even if the
199200
* keyspace does not exist, the method call will not interrupt the flow of the application, thereby allowing
200201
* for flexible and error-tolerant code design.
201202
*
202-
* @param namespace The name of the keyspace to be dropped. This parameter specifies the target keyspace
203+
* @param keyspace The name of the keyspace to be dropped. This parameter specifies the target keyspace
203204
* that should be deleted. The operation will proceed silently and without error even if the
204205
* keyspace does not exist, ensuring consistent behavior.
205206
*/
206-
default void dropKeyspace(String namespace) {
207-
dropKeyspace(namespace, null);
207+
default void dropKeyspace(String keyspace) {
208+
Assert.hasLength(keyspace, "keyspace");
209+
dropKeyspace(keyspace, null);
208210
}
209211

210-
void dropKeyspace(String namespace, BaseOptions<?> options);
212+
void dropKeyspace(String keyspace, BaseOptions<?> options);
211213

212214
/**
213215
* Asynchronously drops (deletes) the specified keyspace from the database. This operation is idempotent, meaning

astra-db-java/src/main/java/com/datastax/astra/client/collections/CollectionDefinition.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import com.datastax.astra.client.core.vector.SimilarityMetric;
2424
import com.datastax.astra.client.core.vector.VectorOptions;
2525
import com.datastax.astra.client.core.vectorize.VectorServiceOptions;
26+
import lombok.Data;
27+
import lombok.Getter;
2628
import lombok.NoArgsConstructor;
2729
import lombok.NonNull;
2830
import lombok.Setter;
@@ -96,24 +98,18 @@ public CollectionDefaultIdTypes getType() {
9698
* Subclass representing the indexing options.
9799
*/
98100
@Setter
101+
@NoArgsConstructor
99102
public static class IndexingOptions {
100103

101104
/**
102105
* If not empty will index everything but those properties.
103106
*/
104-
private List<String> deny;
107+
List<String> deny;
105108

106109
/**
107110
* If not empty will index just those properties.
108111
*/
109-
private List<String> allow;
110-
111-
/**
112-
* Default constructor.
113-
*/
114-
public IndexingOptions() {
115-
// left blank, serialization with jackson
116-
}
112+
List<String> allow;
117113

118114
/**
119115
* Gets deny
@@ -140,9 +136,6 @@ public List<String> getAllow() {
140136
* vector options
141137
*/
142138
public VectorOptions getVector() {
143-
if (vector == null) {
144-
vector = new VectorOptions();
145-
}
146139
return vector;
147140
}
148141

@@ -152,9 +145,6 @@ public VectorOptions getVector() {
152145
* @return indexing options
153146
*/
154147
public IndexingOptions getIndexing() {
155-
if (indexing == null) {
156-
indexing = new IndexingOptions();
157-
}
158148
return indexing;
159149
}
160150

@@ -208,6 +198,9 @@ public CollectionDefinition vectorSimilarity(@NonNull SimilarityMetric metric) {
208198
* @return self reference
209199
*/
210200
public CollectionDefinition indexingDeny(@NonNull String... properties) {
201+
if (getIndexing() == null) {
202+
indexing = new IndexingOptions();
203+
}
211204
if (getIndexing().getAllow() != null) {
212205
throw new IllegalStateException("'indexing.deny' and 'indexing.allow' are mutually exclusive");
213206
}
@@ -222,6 +215,9 @@ public CollectionDefinition indexingDeny(@NonNull String... properties) {
222215
* @return self reference
223216
*/
224217
public CollectionDefinition indexingAllow(String... properties) {
218+
if (getIndexing() == null) {
219+
indexing = new IndexingOptions();
220+
}
225221
if (getIndexing().getDeny() != null) {
226222
throw new IllegalStateException("'indexing.deny' and 'indexing.allow' are mutually exclusive");
227223
}
@@ -237,6 +233,9 @@ public CollectionDefinition indexingAllow(String... properties) {
237233
* @return self reference
238234
*/
239235
public CollectionDefinition vector(int dimension, @NonNull SimilarityMetric function) {
236+
if (getVector() == null) {
237+
vector = new VectorOptions();
238+
}
240239
return vectorSimilarity(function).vectorDimension(dimension);
241240
}
242241

astra-db-java/src/main/java/com/datastax/astra/client/core/commands/BaseOptions.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.datastax.astra.client.core.options.TimeoutOptions;
2727
import com.datastax.astra.internal.command.CommandObserver;
2828
import com.datastax.astra.internal.serdes.DataAPISerializer;
29+
import com.fasterxml.jackson.annotation.JsonIgnore;
2930
import lombok.NoArgsConstructor;
3031

3132
import java.util.Map;
@@ -199,6 +200,9 @@ public T httpClientOptions(HttpClientOptions options) {
199200
*/
200201
@SuppressWarnings("unchecked")
201202
public T timeoutOptions(TimeoutOptions timeoutOptions) {
203+
if (getDataAPIClientOptions() == null) {
204+
this.dataAPIClientOptions = new DataAPIClientOptions();
205+
}
202206
getDataAPIClientOptions().timeoutOptions(timeoutOptions);
203207
return (T) this;
204208
}
@@ -301,6 +305,9 @@ public long getRequestTimeout(TimeoutOptions timeoutOptions, CommandType type) {
301305
* service key
302306
*/
303307
public T timeout(long timeoutMillis, CommandType commandType) {
308+
if (getDataAPIClientOptions() == null) {
309+
dataAPIClientOptions = new DataAPIClientOptions();
310+
}
304311
if (getDataAPIClientOptions().getTimeoutOptions() == null) {
305312
getDataAPIClientOptions().timeoutOptions(new TimeoutOptions());
306313
}
@@ -324,6 +331,7 @@ public T timeout(long timeoutMillis, CommandType commandType) {
324331
*
325332
* @return value of dataAPIClientOptions
326333
*/
334+
@JsonIgnore
327335
public DataAPIClientOptions getDataAPIClientOptions() {
328336
return dataAPIClientOptions;
329337
}
@@ -333,24 +341,33 @@ public DataAPIClientOptions getDataAPIClientOptions() {
333341
*
334342
* @return value of token
335343
*/
344+
@JsonIgnore
336345
public long getTimeout() {
337-
return getTimeout(getDataAPIClientOptions().getTimeoutOptions(), getCommandType());
346+
if (getDataAPIClientOptions() != null && getDataAPIClientOptions().getTimeoutOptions() != null) {
347+
return getTimeout(getDataAPIClientOptions().getTimeoutOptions(), getCommandType());
348+
}
349+
return -1;
338350
}
339351

340352
/**
341353
* Return the HTTP Request Timeout based on the command type
342354
*
343355
* @return value of token
344356
*/
357+
@JsonIgnore
345358
public long getRequestTimeout() {
346-
return getRequestTimeout(getDataAPIClientOptions().getTimeoutOptions(), getCommandType());
359+
if (getDataAPIClientOptions() != null && getDataAPIClientOptions().getTimeoutOptions() != null) {
360+
return getRequestTimeout(getDataAPIClientOptions().getTimeoutOptions(), getCommandType());
361+
}
362+
return -1;
347363
}
348364

349365
/**
350366
* Gets token
351367
*
352368
* @return value of token
353369
*/
370+
@JsonIgnore
354371
public String getToken() {
355372
return token;
356373
}
@@ -360,6 +377,7 @@ public String getToken() {
360377
*
361378
* @return value of commandType
362379
*/
380+
@JsonIgnore
363381
public CommandType getCommandType() {
364382
return commandType;
365383
}
@@ -369,6 +387,7 @@ public CommandType getCommandType() {
369387
*
370388
* @return value of serializer
371389
*/
390+
@JsonIgnore
372391
public DataAPISerializer getSerializer() {
373392
return serializer;
374393
}

astra-db-java/src/main/java/com/datastax/astra/client/core/query/Sort.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public static Sort vector(float[] embeddings) {
122122
* sort instance.
123123
*/
124124
public static Sort vectorize(String vectorize) {
125-
return new Sort(DataAPIKeywords.VECTOR.getKeyword(), null, vectorize, null);
125+
return new Sort(DataAPIKeywords.VECTORIZE.getKeyword(), null, vectorize, null);
126126
}
127127

128128
}

astra-db-java/src/main/java/com/datastax/astra/client/databases/Database.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,8 @@ public List<String> listTableNames() {
404404
* @return
405405
* a stream containing all the names of all the collections in this database
406406
*/
407-
public List<String> listTableNames(ListTablesOptions options) {
408-
return runCommand(Command.create("listTables"), options)
407+
public List<String> listTableNames(ListTablesOptions listTablesOptions) {
408+
return runCommand(Command.create("listTables"), listTablesOptions)
409409
.getStatusKeyAsStringStream("tables")
410410
.toList();
411411
}
@@ -420,11 +420,11 @@ public List<TableDescriptor> listTables() {
420420
* @return
421421
* list of table definitions
422422
*/
423-
public List<TableDescriptor> listTables(ListTablesOptions options) {
423+
public List<TableDescriptor> listTables(ListTablesOptions listTableOptions) {
424424
Command findTables = Command
425425
.create("listTables")
426426
.withOptions(new Document().append("explain", true));
427-
return runCommand(findTables, options)
427+
return runCommand(findTables, listTableOptions)
428428
.getStatusKeyAsList("tables", TableDescriptor.class);
429429
}
430430

@@ -482,7 +482,8 @@ public <T> Table<T> getTable(@NonNull Class<T> rowClass) {
482482

483483
// definition with a proposed bean
484484
public <T> Table<T> createTable(String tableName, TableDefinition tableDefinition, Class<T> rowClass) {
485-
return createTable(tableName, tableDefinition, new CreateTableOptions(), rowClass, new TableOptions());
485+
return createTable(tableName, tableDefinition, new CreateTableOptions(), rowClass,
486+
new TableOptions(this.options.getToken(), this.options.getDataAPIClientOptions()));
486487
}
487488

488489
// definition with default rowClass
@@ -492,7 +493,8 @@ public Table<Row> createTable(String tableName, TableDefinition tableDefinition)
492493

493494
// definition with a proposed bean
494495
public <T> Table<T> createTable(String tableName, TableDefinition tableDefinition, CreateTableOptions createTableOptions, Class<T> rowClass) {
495-
return createTable(tableName, tableDefinition, createTableOptions, rowClass, new TableOptions());
496+
return createTable(tableName, tableDefinition, createTableOptions, rowClass,
497+
new TableOptions(this.options.getToken(), this.options.getDataAPIClientOptions()));
496498
}
497499
public Table<Row> createTable(String tableName, TableDefinition tableDefinition, CreateTableOptions tableOptions) {
498500
return createTable(tableName, tableDefinition, tableOptions, Row.class);

astra-db-java/src/main/java/com/datastax/astra/client/tables/Table.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -388,20 +388,20 @@ public TableInsertManyResult insertMany(List<? extends T> rows) {
388388
return insertMany(rows, new TableInsertManyOptions());
389389
}
390390

391-
public TableInsertManyResult insertMany(List<? extends T> rows, TableInsertManyOptions options) {
391+
public TableInsertManyResult insertMany(List<? extends T> rows, TableInsertManyOptions insertManyOptions) {
392392
Assert.isTrue(rows != null && !rows.isEmpty(), "rows list cannot be null or empty");
393-
Assert.notNull(options, "insertMany options cannot be null");
394-
if (options.concurrency() > 1 && options.ordered()) {
393+
Assert.notNull(insertManyOptions, "insertMany options cannot be null");
394+
if (insertManyOptions.concurrency() > 1 && insertManyOptions.ordered()) {
395395
throw new IllegalArgumentException("Cannot run ordered insert_many concurrently.");
396396
}
397-
if (options.chunkSize() > MAX_CHUNK_SIZE) {
397+
if (insertManyOptions.chunkSize() > MAX_CHUNK_SIZE) {
398398
throw new IllegalArgumentException("Cannot insert more than " + MAX_CHUNK_SIZE + " at a time.");
399399
}
400400
long start = System.currentTimeMillis();
401-
ExecutorService executor = Executors.newFixedThreadPool(options.concurrency());
401+
ExecutorService executor = Executors.newFixedThreadPool(insertManyOptions.concurrency());
402402
List<Future<TableInsertManyResult>> futures = new ArrayList<>();
403-
for (int i = 0; i < rows.size(); i += options.chunkSize()) {
404-
futures.add(executor.submit(getInsertManyResultCallable(rows, options, i)));
403+
for (int i = 0; i < rows.size(); i += insertManyOptions.chunkSize()) {
404+
futures.add(executor.submit(getInsertManyResultCallable(rows, insertManyOptions, i)));
405405
}
406406
executor.shutdown();
407407

astra-db-java/src/main/java/com/datastax/astra/internal/command/AbstractCommandRunner.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@
3131
import com.datastax.astra.internal.api.DataAPIResponse;
3232
import com.datastax.astra.internal.http.RetryHttpClient;
3333
import com.datastax.astra.internal.serdes.DataAPISerializer;
34+
import com.datastax.astra.internal.serdes.DatabaseSerializer;
3435
import com.datastax.astra.internal.utils.Assert;
3536
import com.datastax.astra.internal.utils.CompletableFutures;
37+
import com.dtsx.astra.sdk.db.domain.Database;
3638
import com.evanlennick.retry4j.Status;
3739
import lombok.Getter;
3840
import lombok.extern.slf4j.Slf4j;

0 commit comments

Comments
 (0)