Skip to content

Commit 4d832cf

Browse files
committed
removing the stack from the logs
1 parent c9bf29a commit 4d832cf

File tree

6 files changed

+37
-13
lines changed

6 files changed

+37
-13
lines changed

astra-db-java/src/main/java/com/datastax/astra/client/exception/DataAPIErrorDescriptor.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
* #L%
2121
*/
2222

23+
import com.fasterxml.jackson.annotation.JsonIgnore;
24+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
2325
import lombok.Getter;
2426
import lombok.Setter;
2527

@@ -30,6 +32,7 @@
3032
*/
3133
@Getter
3234
@Setter
35+
@JsonIgnoreProperties({"stackTrace", "suppressed", "cause", "localizedMessage"})
3336
public class DataAPIErrorDescriptor extends RuntimeException {
3437

3538
/**
@@ -77,6 +80,7 @@ public DataAPIErrorDescriptor() {
7780
* @return A concatenated string representing the full error message, which may include the exception class name,
7881
* the error code in parentheses, and the detailed error message. Each element is included only if it is not {@code null}.
7982
*/
83+
@JsonIgnore
8084
public String getErrorMessage() {
8185
StringBuilder sb = new StringBuilder();
8286
if (exceptionClass != null) {
@@ -90,4 +94,11 @@ public String getErrorMessage() {
9094
}
9195
return sb.toString().trim();
9296
}
97+
98+
@Override
99+
@JsonIgnore
100+
public String getLocalizedMessage() {
101+
return super.getLocalizedMessage();
102+
}
103+
93104
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,10 @@ public EntityBeanDefinition(Class<T> clazz) {
152152
}
153153

154154
/**
155-
* Build the partition Key based on annotated fields.
155+
* Build the partition Key based on annotated fields with @PartitionBy with position.
156156
*
157157
* @return
158-
* list of partition keys
158+
* An ordered list of partition keys (partition key)
159159
*/
160160
public List<String> getPartitionBy() {
161161
return getFields().values().stream()
@@ -171,10 +171,10 @@ public List<String> getPartitionBy() {
171171
}
172172

173173
/**
174-
* Build the clustering Key based on annotated fields.
174+
* Build the partition sort based on annotated fields @PartitionSort with position and order.
175175
*
176176
* @return
177-
* list of clustering keys
177+
* an ordered map representing the partition sort (clustering columns)
178178
*/
179179
public Map<String, Integer> getPartitionSort() {
180180
List<EntityFieldDefinition> fields = getFields().values().stream()

astra-db-java/src/main/java/com/datastax/astra/internal/api/DataAPIResponse.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
*/
2222

2323
import com.datastax.astra.client.collections.documents.Document;
24+
import com.datastax.astra.client.core.commands.Command;
2425
import com.datastax.astra.client.exception.DataAPIErrorDescriptor;
26+
import com.datastax.astra.client.exception.UnexpectedDataAPIResponseException;
2527
import com.datastax.astra.internal.serdes.DataAPISerializer;
2628
import com.datastax.astra.internal.utils.Assert;
2729
import com.fasterxml.jackson.annotation.JsonIgnore;
@@ -89,7 +91,9 @@ public DataAPIResponse() {
8991
*/
9092
@SuppressWarnings("unchecked")
9193
public Stream<String> getStatusKeyAsStringStream(@NonNull String key) {
92-
Assert.isTrue(status.containsKey(key), "Key not found in status map");
94+
if (!status.containsKey(key)) {
95+
throw new UnexpectedDataAPIResponseException(new Command(), this, "Key '" + key + "' has not been found in response.");
96+
}
9397
return ((ArrayList<String>) status.get(key)).stream();
9498
}
9599

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,18 @@ public abstract class AbstractDatabaseTest extends AbstractDataAPITest {
4545
// --------- Collections --------------
4646
// ------------------------------------
4747

48+
public void cleanupCollections() {
49+
// Removing a few collections to test mores elements
50+
getDatabase().listCollectionNames().forEach(c -> {
51+
System.out.println("Dropping collection ..." + c);
52+
getDatabase().dropCollection(c);
53+
});
54+
}
55+
4856
@Test
4957
@Order(1)
5058
public void shouldCreateCollectionSimple() {
59+
cleanupCollections();
5160
// When
5261
getDatabase().createCollection(COLLECTION_SIMPLE);
5362
assertThat(getDatabase().collectionExists(COLLECTION_SIMPLE)).isTrue();
@@ -227,8 +236,6 @@ public void shouldCollectionWorkWithUUIDs() {
227236
resultsList.getInsertedIds().forEach(id -> assertThat(id).isInstanceOf(UUID.class));
228237
}
229238

230-
231-
232239
@Test
233240
@Order(11)
234241
public void shouldCollectionWorkWithObjectIds() {
@@ -263,13 +270,14 @@ public void shouldCollectionWorkWithObjectIds() {
263270
product.setCode(UUID.randomUUID());
264271
product.setPrice(0d);
265272
Collection<ProductObjectId> collectionObjectId = getDatabase().createCollection(COLLECTION_OBJECTID,
266-
new CollectionDefinition().defaultId(OBJECT_ID), ProductObjectId.class);
273+
new CollectionDefinition().defaultId(OBJECT_ID), ProductObjectId.class);
267274
collectionObjectId.deleteAll();
268275
collectionObjectId.insertOne(product);
269276
Optional<ProductObjectId> productObjectId = collectionObjectId.findOne(eq(product.getId()));
270277
assertThat(productObjectId).isPresent();
271278
}
272279

280+
273281
@Test
274282
@Order(12)
275283
public void shouldCollectionWorkWithUUIDv6() {
@@ -302,6 +310,7 @@ public void shouldCollectionWorkWithUUIDv6() {
302310
@Test
303311
@Order(13)
304312
public void shouldCollectionWorkWithUUIDv7() {
313+
cleanupCollections();
305314
// When
306315
Collection<Document> collectionUUID = getDatabase()
307316
.createCollection(COLLECTION_UUID_V7, new CollectionDefinition()

astra-db-java/src/test/java/com/datastax/astra/test/integration/local/LocalDatabaseITTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
import com.datastax.astra.client.core.options.DataAPIClientOptions;
88
import com.datastax.astra.client.databases.Database;
99
import com.datastax.astra.client.core.auth.UsernamePasswordTokenProvider;
10+
import com.datastax.astra.client.exception.DataAPIException;
1011
import com.datastax.astra.client.exception.DataAPIResponseException;
1112
import com.datastax.astra.client.core.commands.Command;
1213
import com.datastax.astra.client.collections.documents.Document;
1314
import com.datastax.astra.client.core.http.HttpProxy;
15+
import com.datastax.astra.client.exception.UnexpectedDataAPIResponseException;
1416
import com.datastax.astra.test.integration.AbstractDatabaseTest;
1517
import com.dtsx.astra.sdk.db.domain.CloudProviderType;
1618
import com.dtsx.astra.sdk.utils.AstraEnvironment;
@@ -56,10 +58,8 @@ void shouldRunInvalidCommand() {
5658
//getDatabase().registerListener("demo", new MockCommandObserver());
5759
getDatabase().runCommand(new Command("invalid", new Document()));
5860
//getDatabase().deleteListener("demo");
59-
} catch(DataAPIResponseException dat) {
60-
assertThat(dat.getMessage()).contains("No \"invalid\" command found ");
61-
assertThat(dat.getApiErrors()).isNotEmpty();
62-
assertThat(dat.getCommandsList()).isNotEmpty();
61+
} catch(DataAPIException dat) {
62+
assertThat(dat.getMessage()).contains("COMMAND_UNKNOWN");;
6363
}
6464
}
6565

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.local;
1+
package com.datastax.astra.test.unit;
22

33
import com.datastax.astra.client.DataAPIClients;
44
import com.datastax.astra.client.core.query.Filter;

0 commit comments

Comments
 (0)