WAL reads should fail with exception on encrypted content.
@@ -170,6 +170,73 @@ public class OCASDiskWriteAheadLogIT {
}
}
+ @Test
+ public void testAddSingleOnePageRecordNonEncrypted() throws Exception {
+ final String aesKeyEncoded = "T1JJRU5UREJfSVNfQ09PTA==";
+ final byte[] aesKey = Base64.getDecoder().decode(aesKeyEncoded);
+ final byte[] iv = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
+
+ final int iterations = 10;
+
+ for (int i = 0; i < iterations; i++) {
+ OFileUtils.deleteRecursively(testDirectory.toFile());
+
+ final long seed = System.nanoTime();
+ try {
+ final Random random = new Random(seed);
+
+ OCASDiskWriteAheadLog wal = new OCASDiskWriteAheadLog("walTest", testDirectory, testDirectory, 100, 64, aesKey, iv,
+ Integer.MAX_VALUE, Integer.MAX_VALUE, 20, true, Locale.US, -1, -1, 1000, true, false, true, 10);
+
+ Assert.assertEquals(wal.begin(), new OLogSequenceNumber(1, OCASWALPage.RECORDS_OFFSET));
+ Assert.assertEquals(wal.end(), new OLogSequenceNumber(1, OCASWALPage.RECORDS_OFFSET));
+
+ TestRecord walRecord = new TestRecord(random, wal.pageSize(), 1);
+ final OLogSequenceNumber lsn = wal.log(walRecord);
+
+ Assert.assertEquals(wal.begin(), new OLogSequenceNumber(1, OCASWALPage.RECORDS_OFFSET));
+ Assert.assertEquals(wal.end(), lsn);
+
+ List<OWriteableWALRecord> records = wal.read(lsn, 10);
+ Assert.assertEquals(1, records.size());
+ TestRecord readRecord = (TestRecord) records.get(0);
+
+ Assert.assertArrayEquals(walRecord.data, readRecord.data);
+ Assert.assertEquals(lsn, walRecord.getLsn());
+ wal.close();
+
+ wal = new OCASDiskWriteAheadLog("walTest", testDirectory, testDirectory, 100, 64,null, null, Integer.MAX_VALUE,
+ Integer.MAX_VALUE, 20, true, Locale.US, -1, -1, 1000, true, false, true, 10);
+
+ Assert.assertEquals(wal.begin(), new OLogSequenceNumber(1, OCASWALPage.RECORDS_OFFSET));
+ Assert.assertEquals(wal.end(), new OLogSequenceNumber(2, OCASWALPage.RECORDS_OFFSET));
+
+ wal.flush();
+
+ Assert.assertEquals(wal.begin(), new OLogSequenceNumber(1, OCASWALPage.RECORDS_OFFSET));
+ Assert.assertEquals(wal.end(), new OLogSequenceNumber(2, OCASWALPage.RECORDS_OFFSET));
+
+ try {
+ wal.read(lsn, 10);
+ Assert.fail();
+ } catch (Exception e) {
+ //ignore
+ }
+
+ wal.close();
+
+ Thread.sleep(1);
+
+ if (i > 0 && i % 1000 == 0) {
+ System.out.printf("%d iterations out of %d were passed\n", i, iterations);
+ }
+ } catch (Exception | Error e) {
+ System.out.println("testAddSingleOnePageRecord : " + seed);
+ throw e;
+ }
+ }
+ }
+
@Test
public void testAddSingleRecordSeveralPages() throws Exception {
final int iterations = 10;
