@@ -73,13 +73,6 @@ public void shouldCreateCorrectMetadataFileForLatestVersionForNewDb() throws Exc
7373 }
7474 }
7575
76- private void mockCommonConfiguration (
77- final Path tempDataDir , final Path tempDatabaseDir , final DataStorageFormat format ) {
78- when (commonConfiguration .getStoragePath ()).thenReturn (tempDatabaseDir );
79- when (commonConfiguration .getDataPath ()).thenReturn (tempDataDir );
80- lenient ().when (commonConfiguration .getDatabaseFormat ()).thenReturn (format );
81- }
82-
8376 @ Test
8477 public void shouldFailIfDbExistsAndNoMetadataFileFound () throws Exception {
8578 final Path tempDataDir = temporaryFolder .resolve ("data" );
@@ -122,7 +115,7 @@ public void shouldDetectCorrectMetadataV1() throws Exception {
122115 }
123116
124117 @ Test
125- public void shouldDetectCorrectVersionInCaseOfRollback () throws Exception {
118+ public void shouldFailInCaseOfUnmanagedRollback () throws Exception {
126119 final Path tempDataDir = temporaryFolder .resolve ("data" );
127120 final Path tempDatabaseDir = temporaryFolder .resolve ("db" );
128121 Files .createDirectories (tempDatabaseDir );
@@ -133,22 +126,20 @@ public void shouldDetectCorrectVersionInCaseOfRollback() throws Exception {
133126
134127 final RocksDBKeyValueStorageFactory storageFactory =
135128 new RocksDBKeyValueStorageFactory (
136- () -> rocksDbConfiguration ,
137- segments ,
138- BONSAI ,
139- RocksDBMetricsFactory .PUBLIC_ROCKS_DB_METRICS );
129+ () -> rocksDbConfiguration , segments , RocksDBMetricsFactory .PUBLIC_ROCKS_DB_METRICS );
140130
141131 storageFactory .create (segment , commonConfiguration , metricsSystem );
142132 storageFactory .close ();
143133
134+ Utils .createDatabaseMetadataV2 (tempDataDir , BONSAI , 1 );
135+
144136 final RocksDBKeyValueStorageFactory rolledbackStorageFactory =
145137 new RocksDBKeyValueStorageFactory (
146- () -> rocksDbConfiguration ,
147- segments ,
148- FOREST ,
149- RocksDBMetricsFactory .PUBLIC_ROCKS_DB_METRICS );
150- rolledbackStorageFactory .create (segment , commonConfiguration , metricsSystem );
151- rolledbackStorageFactory .close ();
138+ () -> rocksDbConfiguration , segments , RocksDBMetricsFactory .PUBLIC_ROCKS_DB_METRICS );
139+ assertThatThrownBy (
140+ () -> rolledbackStorageFactory .create (segment , commonConfiguration , metricsSystem ))
141+ .isInstanceOf (StorageException .class )
142+ .hasMessageStartingWith ("Database unsafe downgrade detect" );
152143 }
153144
154145 @ Test
@@ -167,12 +158,12 @@ public void shouldThrowExceptionWhenVersionNumberIsInvalid() throws Exception {
167158 segments ,
168159 RocksDBMetricsFactory .PUBLIC_ROCKS_DB_METRICS )
169160 .create (segment , commonConfiguration , metricsSystem ))
170- .isInstanceOf (StorageException .class );
161+ .isInstanceOf (StorageException .class )
162+ .hasMessageStartingWith ("Unsupported db version" );
171163 }
172164
173165 @ Test
174- public void shouldThrowExceptionWhenExistingDatabaseVersionDifferentFromConfig ()
175- throws Exception {
166+ public void shouldThrowExceptionWhenExistingDatabaseFormatDiffersFromConfig () throws Exception {
176167
177168 final DataStorageFormat actualDatabaseFormat = FOREST ;
178169 final DataStorageFormat expectedDatabaseFormat = BONSAI ;
@@ -185,12 +176,6 @@ public void shouldThrowExceptionWhenExistingDatabaseVersionDifferentFromConfig()
185176
186177 Utils .createDatabaseMetadataV2 (tempDataDir , FOREST , 2 );
187178
188- String exceptionMessage =
189- String .format (
190- "Database format mismatch: DB at %s is %s but config expects %s. "
191- + "Please check your config." ,
192- tempDataDir .toAbsolutePath (), actualDatabaseFormat , expectedDatabaseFormat );
193-
194179 assertThatThrownBy (
195180 () ->
196181 new RocksDBKeyValueStorageFactory (
@@ -199,7 +184,10 @@ public void shouldThrowExceptionWhenExistingDatabaseVersionDifferentFromConfig()
199184 RocksDBMetricsFactory .PUBLIC_ROCKS_DB_METRICS )
200185 .create (segment , commonConfiguration , metricsSystem ))
201186 .isInstanceOf (StorageException .class )
202- .hasMessage (exceptionMessage );
187+ .hasMessage (
188+ "Database format mismatch: DB at %s is %s but config expects %s. "
189+ + "Please check your config." ,
190+ tempDataDir .toAbsolutePath (), actualDatabaseFormat , expectedDatabaseFormat );
203191 }
204192
205193 @ Test
@@ -240,9 +228,11 @@ public void shouldThrowExceptionWhenMetaDataFileIsCorrupted() throws Exception {
240228 segments ,
241229 RocksDBMetricsFactory .PUBLIC_ROCKS_DB_METRICS )
242230 .create (segment , commonConfiguration , metricsSystem ))
243- .isInstanceOf (IllegalStateException .class );
231+ .isInstanceOf (IllegalStateException .class )
232+ .hasMessageStartingWith ("Invalid metadata file" );
233+ ;
244234
245- Utils .createDatabaseMetadataRaw (tempDataDir , "{\" version\" : \" iomedae \" }" );
235+ Utils .createDatabaseMetadataRaw (tempDataDir , "{\" version\" =1 }" );
246236
247237 assertThatThrownBy (
248238 () ->
@@ -251,7 +241,9 @@ public void shouldThrowExceptionWhenMetaDataFileIsCorrupted() throws Exception {
251241 segments ,
252242 RocksDBMetricsFactory .PUBLIC_ROCKS_DB_METRICS )
253243 .create (segment , commonConfiguration , metricsSystem ))
254- .isInstanceOf (IllegalStateException .class );
244+ .isInstanceOf (IllegalStateException .class )
245+ .hasMessageStartingWith ("Invalid metadata file" );
246+ ;
255247 }
256248
257249 @ Test
@@ -276,4 +268,11 @@ public void shouldCreateDBCorrectlyIfSymlink() throws Exception {
276268 .isEqualTo (BaseVersionedStorageFormat .FOREST_WITH_VARIABLES );
277269 }
278270 }
271+
272+ private void mockCommonConfiguration (
273+ final Path tempDataDir , final Path tempDatabaseDir , final DataStorageFormat format ) {
274+ when (commonConfiguration .getStoragePath ()).thenReturn (tempDatabaseDir );
275+ when (commonConfiguration .getDataPath ()).thenReturn (tempDataDir );
276+ lenient ().when (commonConfiguration .getDatabaseFormat ()).thenReturn (format );
277+ }
279278}
0 commit comments