|
27 | 27 | import com.google.common.base.Charsets;
|
28 | 28 | import org.junit.jupiter.api.Tag;
|
29 | 29 | import org.junit.jupiter.api.Test;
|
| 30 | +import org.junit.jupiter.params.ParameterizedTest; |
| 31 | +import org.junit.jupiter.params.provider.MethodSource; |
| 32 | + |
| 33 | +import java.util.stream.IntStream; |
30 | 34 |
|
31 | 35 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
32 | 36 | import static org.junit.jupiter.api.Assertions.assertNull;
|
33 | 37 | import static org.junit.jupiter.api.Assertions.assertThrows;
|
34 | 38 |
|
35 | 39 | /**
|
36 |
| - * Tests related to upgrading/downgrading the format version. |
| 40 | + * Tests related to interacting with the format version. |
37 | 41 | */
|
38 | 42 | @Tag(Tags.RequiresFDB)
|
39 | 43 | public class FDBRecordStoreFormatVersionTest extends FDBRecordStoreTestBase {
|
@@ -109,4 +113,65 @@ public void testAccessUserFieldAtOldFormatVersion() {
|
109 | 113 | }
|
110 | 114 | }
|
111 | 115 |
|
| 116 | + public static IntStream testOpenWithProvidedBadVersion() { |
| 117 | + return IntStream.of(-1, 0, FDBRecordStore.MAX_SUPPORTED_FORMAT_VERSION + 1); |
| 118 | + } |
| 119 | + |
| 120 | + @ParameterizedTest |
| 121 | + @MethodSource |
| 122 | + void testOpenWithProvidedBadVersion(int version) { |
| 123 | + try (FDBRecordContext context = openContext()) { |
| 124 | + assertThrows(UnsupportedFormatVersionException.class, |
| 125 | + () -> getStoreBuilder(context, simpleMetaData(NO_HOOK)) |
| 126 | + .setFormatVersion(version)); |
| 127 | + } |
| 128 | + } |
| 129 | + |
| 130 | + public static IntStream testOpenWithExistingBadVersion() { |
| 131 | + return IntStream.of(-1, 0, FDBRecordStore.MAX_SUPPORTED_FORMAT_VERSION + 1); |
| 132 | + } |
| 133 | + |
| 134 | + @ParameterizedTest |
| 135 | + @MethodSource |
| 136 | + void testOpenWithExistingBadVersion(int version) { |
| 137 | + try (FDBRecordContext context = openContext()) { |
| 138 | + recordStore = getStoreBuilder(context, simpleMetaData(NO_HOOK)) |
| 139 | + .setFormatVersion(FDBRecordStore.MAX_SUPPORTED_FORMAT_VERSION) |
| 140 | + .create(); |
| 141 | + recordStore.saveStoreHeader(recordStore.getRecordStoreState().getStoreHeader() |
| 142 | + .toBuilder() |
| 143 | + .setFormatVersion(version) |
| 144 | + .build()); |
| 145 | + commit(context); |
| 146 | + } |
| 147 | + |
| 148 | + try (FDBRecordContext context = openContext()) { |
| 149 | + final FDBRecordStore.Builder storeBuilder = getStoreBuilder(context, simpleMetaData(NO_HOOK)); |
| 150 | + assertThrows(UnsupportedFormatVersionException.class, () -> storeBuilder |
| 151 | + .setFormatVersion(FDBRecordStore.MAX_SUPPORTED_FORMAT_VERSION) |
| 152 | + .uncheckedOpen()); |
| 153 | + } |
| 154 | + try (FDBRecordContext context = openContext()) { |
| 155 | + final FDBRecordStore.Builder storeBuilder = getStoreBuilder(context, simpleMetaData(NO_HOOK)); |
| 156 | + assertThrows(UnsupportedFormatVersionException.class, () -> storeBuilder |
| 157 | + .setFormatVersion(FDBRecordStore.MAX_SUPPORTED_FORMAT_VERSION) |
| 158 | + .open()); |
| 159 | + } |
| 160 | + } |
| 161 | + |
| 162 | + static IntStream testUnopenedVersion() { |
| 163 | + return IntStream.of(FDBRecordStore.DEFAULT_FORMAT_VERSION, FDBRecordStore.INFO_ADDED_FORMAT_VERSION, |
| 164 | + FDBRecordStore.MAX_SUPPORTED_FORMAT_VERSION); |
| 165 | + } |
| 166 | + |
| 167 | + @ParameterizedTest |
| 168 | + @MethodSource |
| 169 | + void testUnopenedVersion(int version) { |
| 170 | + try (FDBRecordContext context = openContext()) { |
| 171 | + recordStore = getStoreBuilder(context, simpleMetaData(NO_HOOK)) |
| 172 | + .setFormatVersion(version) |
| 173 | + .build(); |
| 174 | + assertEquals(version, recordStore.getFormatVersion()); |
| 175 | + } |
| 176 | + } |
112 | 177 | }
|
0 commit comments