@@ -88,6 +88,8 @@ public void before() throws IOException {
8888 conn .add (S5 , CTX_2 );
8989 }
9090 backupFile (dataDir , "values.dat" );
91+ backupFile (dataDir , "values.id" );
92+ backupFile (dataDir , "values.hash" );
9193 }
9294
9395 public static void overwriteByteInFile (File valuesFile , long pos , int newVal ) throws IOException {
@@ -116,7 +118,7 @@ public static void backupFile(File dataDir, String s) throws IOException {
116118 File backupFile = new File (dataDir , s + ".bak" );
117119
118120 if (!valuesFile .exists ()) {
119- throw new IOException ("values.dat does not exist and cannot be backed up." );
121+ throw new IOException (s + " does not exist and cannot be backed up." );
120122 }
121123
122124 // Copy values.dat to values.dat.bak
@@ -128,7 +130,7 @@ public static void restoreFile(File dataDir, String s) throws IOException {
128130 File backupFile = new File (dataDir , s + ".bak" );
129131
130132 if (!backupFile .exists ()) {
131- throw new IOException ("Backup file values.dat .bak does not exist." );
133+ throw new IOException ("Backup file " + s + " .bak does not exist." );
132134 }
133135
134136 // Copy values.dat.bak back to values.dat
@@ -196,9 +198,53 @@ public void testCorruptValuesDatFileEntireValuesDatFile() throws IOException {
196198
197199 List <Statement > list = getStatements ();
198200 assertEquals (6 , list .size ());
201+ }
202+ }
203+
204+ @ Test
205+ public void testCorruptLastByteOfValuesDatFile () throws IOException {
206+ repo .shutDown ();
207+ File valuesFile = new File (dataDir , "values.dat" );
208+ long fileSize = valuesFile .length ();
209+
210+ overwriteByteInFile (valuesFile , fileSize - 1 , 0x0 );
211+
212+ repo .init ();
213+
214+ List <Statement > list = getStatements ();
215+ assertEquals (6 , list .size ());
216+ }
217+
218+ @ Test
219+ public void testCorruptValuesIdFile () throws IOException {
220+ repo .shutDown ();
221+ File valuesIdFile = new File (dataDir , "values.id" );
222+ long fileSize = valuesIdFile .length ();
199223
224+ for (long i = 4 ; i < fileSize ; i ++) {
225+ restoreFile (dataDir , "values.id" );
226+ overwriteByteInFile (valuesIdFile , i , 0x0 );
227+ repo .init ();
228+ List <Statement > list = getStatements ();
229+ assertEquals (6 , list .size (), "Failed at byte position " + i );
230+ repo .shutDown ();
200231 }
232+ }
201233
234+ @ Test
235+ public void testCorruptValuesHashFile () throws IOException {
236+ repo .shutDown ();
237+ File valuesHashFile = new File (dataDir , "values.hash" );
238+ long fileSize = valuesHashFile .length ();
239+
240+ for (long i = 4 ; i < fileSize ; i ++) {
241+ restoreFile (dataDir , "values.hash" );
242+ overwriteByteInFile (valuesHashFile , i , 0x0 );
243+ repo .init ();
244+ List <Statement > list = getStatements ();
245+ assertEquals (6 , list .size (), "Failed at byte position " + i );
246+ repo .shutDown ();
247+ }
202248 }
203249
204250 @ NotNull
@@ -226,7 +272,10 @@ private List<Statement> getStatements() {
226272 }
227273
228274 @ AfterEach
229- public void after () {
275+ public void after () throws IOException {
230276 repo .shutDown ();
277+ restoreFile (dataDir , "values.hash" );
278+ restoreFile (dataDir , "values.id" );
279+ restoreFile (dataDir , "values.dat" );
231280 }
232281}
0 commit comments