Skip to content

Commit 5790298

Browse files
committed
Prepare version storage
1 parent 4e4b8d4 commit 5790298

File tree

3 files changed

+83
-2
lines changed

3 files changed

+83
-2
lines changed

server/src/main/java/com/adobe/testing/s3mock/store/ObjectStore.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public class ObjectStore extends StoreBase {
5454
private static final Logger LOG = LoggerFactory.getLogger(ObjectStore.class);
5555
private static final String META_FILE = "objectMetadata.json";
5656
private static final String DATA_FILE = "binaryData";
57+
private static final String VERSIONS_FILE = "versions.json";
5758

5859
/**
5960
* This map stores one lock object per S3Object ID.
@@ -471,11 +472,11 @@ private Path getObjectFolderPath(BucketMetadata bucket, UUID id) {
471472
}
472473

473474
private Path getMetaFilePath(BucketMetadata bucket, UUID id) {
474-
return Paths.get(getObjectFolderPath(bucket, id).toString(), META_FILE);
475+
return getObjectFolderPath(bucket, id).resolve(META_FILE);
475476
}
476477

477478
private Path getDataFilePath(BucketMetadata bucket, UUID id) {
478-
return Paths.get(getObjectFolderPath(bucket, id).toString(), DATA_FILE);
479+
return getObjectFolderPath(bucket, id).resolve(DATA_FILE);
479480
}
480481

481482
private void writeMetafile(BucketMetadata bucket, S3ObjectMetadata s3ObjectMetadata) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2017-2024 Adobe.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.adobe.testing.s3mock.store;
18+
19+
import java.util.HashMap;
20+
import java.util.Map;
21+
import java.util.UUID;
22+
import java.util.concurrent.atomic.AtomicInteger;
23+
24+
public record S3ObjectVersions(
25+
UUID id,
26+
Map<Integer, String> versions,
27+
AtomicInteger latestVersionPointer
28+
) {
29+
30+
public S3ObjectVersions(UUID id) {
31+
this(id, new HashMap<>(), new AtomicInteger(0));
32+
}
33+
34+
public String createVersion() {
35+
String versionId = UUID.randomUUID().toString();
36+
versions.put(latestVersionPointer.incrementAndGet(), versionId);
37+
return versionId;
38+
}
39+
40+
public String getLatestVersion() {
41+
return versions.get(latestVersionPointer.get());
42+
}
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2017-2024 Adobe.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.adobe.testing.s3mock.store;
18+
19+
import static org.assertj.core.api.Assertions.assertThat;
20+
21+
import java.util.UUID;
22+
import org.junit.jupiter.api.Test;
23+
24+
class S3ObjectVersionsTest {
25+
26+
@Test
27+
void testVersions() {
28+
var iut = new S3ObjectVersions(UUID.randomUUID());
29+
assertThat(iut.getLatestVersion()).isNull();
30+
assertThat(iut.latestVersionPointer().get()).isZero();
31+
32+
var version = iut.createVersion();
33+
assertThat(version).isNotBlank();
34+
assertThat(iut.latestVersionPointer().get()).isOne();
35+
assertThat(iut.getLatestVersion()).isEqualTo(version);
36+
}
37+
}

0 commit comments

Comments
 (0)