diff --git a/src/main/java/io/floci/aws/services/s3vectors/S3VectorsService.java b/src/main/java/io/floci/aws/services/s3vectors/S3VectorsService.java index 6127f2750b..93a84b6a36 100644 --- a/src/main/java/io/floci/aws/services/s3vectors/S3VectorsService.java +++ b/src/main/java/io/floci/aws/services/s3vectors/S3VectorsService.java @@ -49,6 +49,9 @@ public class S3VectorsService implements StoredResourceArns { /** S3 Vectors' not-found messages (measured on AWS). */ private static final String NO_SUCH_BUCKET = "The specified vector bucket could not be found"; private static final String NO_SUCH_INDEX = "The specified index could not be found"; + /** S3 Vectors' messages for a create under a name already taken (measured on AWS). */ + private static final String BUCKET_EXISTS = "A vector bucket with the specified name already exists"; + private static final String INDEX_EXISTS = "An index with the specified name already exists"; private static final Logger LOG = Logger.getLogger(S3VectorsService.class); private static final ObjectReader STRICT_JSON_READER = new ObjectMapper().reader().with(DeserializationFeature.FAIL_ON_TRAILING_TOKENS); @@ -105,7 +108,7 @@ public class S3VectorsService implements StoredResourceArns { synchronized (lockFor(bucketName, region)) { String key = buildStorageKey(region, bucketName); if (store.get(key).isPresent()) { - throw new AwsException("ConflictException", "The vector bucket " + bucketName + " already exists.", 409); + throw new AwsException("ConflictException", BUCKET_EXISTS, 409); } String arn = buildBucketArn(region, bucketName); VectorBucket bucket = new VectorBucket(bucketName, arn, @@ -420,7 +423,7 @@ public class S3VectorsService implements StoredResourceArns { synchronized (lockFor(bucketName, region)) { VectorBucket bucket = getVectorBucket(bucketName, region); if (bucket.getIndexes().containsKey(indexName)) { - throw new AwsException("ConflictException", "The index " + indexName + " already exists.", 409); + throw new AwsException("ConflictException", INDEX_EXISTS, 409); } String arn = buildIndexArn(region, bucketName, indexName); diff --git a/src/test/java/io/floci/aws/services/s3vectors/S3VectorsIntegrationTest.java b/src/test/java/io/floci/aws/services/s3vectors/S3VectorsIntegrationTest.java index 55c9d76420..688a773bfa 100644 --- a/src/test/java/io/floci/aws/services/s3vectors/S3VectorsIntegrationTest.java +++ b/src/test/java/io/floci/aws/services/s3vectors/S3VectorsIntegrationTest.java @@ -43,6 +43,21 @@ class S3VectorsIntegrationTest { .then() .statusCode(200) .body("vectorBucketArn", containsString("arn:aws:s3vectors:")); + + // A second create under the taken name, with S3 Vectors' message (measured on AWS) + given() + .contentType(JSON_CONTENT_TYPE) + .body(""" + { + "vectorBucketName": "%s" + } + """.formatted(BUCKET_NAME)) + .when() + .post("/CreateVectorBucket") + .then() + .statusCode(409) + .body("__type", equalTo("ConflictException")) + .body("message", equalTo("A vector bucket with the specified name already exists")); } @Test @@ -96,6 +111,25 @@ class S3VectorsIntegrationTest { .then() .statusCode(200) .body("indexArn", containsString("arn:aws:s3vectors:")); + + // A second create under the taken name, with S3 Vectors' message (measured on AWS) + given() + .contentType(JSON_CONTENT_TYPE) + .body(""" + { + "vectorBucketName": "%s", + "indexName": "%s", + "dimension": 3, + "distanceMetric": "cosine", + "dataType": "float32" + } + """.formatted(BUCKET_NAME, INDEX_NAME)) + .when() + .post("/CreateIndex") + .then() + .statusCode(409) + .body("__type", equalTo("ConflictException")) + .body("message", equalTo("An index with the specified name already exists")); } @Test