Skip to content

Commit 6a39d0d

Browse files
committed
fix(gh-1162): ensure NitriteId serialization is compatible with previous versions
1 parent 9806e58 commit 6a39d0d

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ test.log
452452
/build
453453
!no2-old.db
454454
!no2-v3.db
455+
!no2-v4.3.0.db
455456
.diffblue
456457
infer-out
457458
secring.gpg

nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/NitriteTest.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import java.io.InputStream;
5454
import java.nio.file.Files;
5555
import java.nio.file.Paths;
56+
import java.nio.file.StandardCopyOption;
5657
import java.text.ParseException;
5758
import java.text.SimpleDateFormat;
5859
import java.util.*;
@@ -622,7 +623,7 @@ public void run() {
622623
log.error("Error in thread", e);
623624
}
624625
}
625-
};
626+
}
626627

627628
Thread t0 = new Thread(new ThreadRunner());
628629
Thread t1 = new Thread(new ThreadRunner());
@@ -682,6 +683,32 @@ public void testReadOnlyMode() {
682683
deleteDb(fileName);
683684
}
684685

686+
@Test
687+
public void testIssue1162() throws IOException {
688+
689+
// setup no2-v4.3.0.db as a temp file
690+
var databasePath = Files.createTempFile("temp-no2-v4.3.0", ".db");
691+
var templateDb = Objects.requireNonNull(NitriteTest.class.getResourceAsStream("/no2-v4.3.0.db"));
692+
Files.copy(templateDb, databasePath, StandardCopyOption.REPLACE_EXISTING);
693+
694+
var module = MVStoreModule.withConfig()
695+
.filePath(databasePath.toAbsolutePath().toFile())
696+
.build();
697+
698+
var database = Nitrite.builder()
699+
.loadModule(module)
700+
.openOrCreate();
701+
702+
try (database) {
703+
var collection = database.getCollection("myCollection");
704+
assertEquals(1, collection.size());
705+
706+
var firstPerson = collection.find().firstOrNull();
707+
assertNotNull(firstPerson);
708+
assertEquals(1970829645337976832L, firstPerson.getId().getIdValue());
709+
}
710+
}
711+
685712
@Data
686713
@AllArgsConstructor
687714
@NoArgsConstructor
16 KB
Binary file not shown.

nitrite/src/main/java/org/dizitart/no2/collection/NitriteId.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import lombok.EqualsAndHashCode;
2020
import lombok.Getter;
21+
2122
import org.dizitart.no2.exceptions.InvalidIdException;
2223

2324
import java.io.IOException;
@@ -48,7 +49,7 @@ public final class NitriteId implements Comparable<NitriteId>, Serializable {
4849
private static final SnowflakeIdGenerator generator = new SnowflakeIdGenerator();
4950

5051
/** The underlying value of the NitriteId. */
51-
private long idValue;
52+
private transient long idValue;
5253

5354
private NitriteId() {
5455
this.idValue = generator.getId();

0 commit comments

Comments
 (0)