Beispiel #1
0
  @Test
  public void testRecoveryCorruptMessage() throws IOException {
    List<Record> records = StoreTestUtils.randomRecords(10);
    putAll(records);

    // append a message with a crc that won't possibly validate
    Record invalid = new Record(ByteBuffer.wrap(StoreTestUtils.randomBytes(10)));
    store.log().append(invalid);
    this.store.close();
    this.store = new HashStore(config);
    // assertEquals("Same records should be present after close and re-open", records,
    // records(store));
  }
Beispiel #2
0
 @Test
 public void testNormalRecovery() throws IOException {
   List<Record> records = StoreTestUtils.randomRecords(10);
   putAll(records);
   this.store.close();
   this.store = new HashStore(config);
   assertEquals("Same records should be present after close and re-open", records, records(store));
 }
Beispiel #3
0
 @Test
 public void testRecoveryWithAdditionalEmptyFile() throws IOException {
   List<Record> records = StoreTestUtils.randomRecords(10);
   putAll(records);
   this.store.close();
   // recreate without closing, we should have trailing empty bytes on the end of the log
   this.store = new HashStore(config);
   assertEquals("Same records should be present after close and re-open", records, records(store));
 }
Beispiel #4
0
  @Test
  public void testRecoveryBadMessageLength() throws IOException {
    List<Record> records = StoreTestUtils.randomRecords(10);
    putAll(records);

    // now test a bunch of bad message lengths
    testRecoveryWithBadMessageSize(records, 0);
    // testRecoveryWithBadMessageSize(records, Integer.MAX_VALUE);
    testRecoveryWithBadMessageSize(records, 5);
  }
Beispiel #5
0
 @Test
 public void testGc() throws IOException {
   // TODO: need to ensure the gc happens before the assertion
   int numRecords = this.store.config().segmentSize();
   List<Record> records = StoreTestUtils.randomRecords(numRecords);
   // write all the records a few times to incur some garbage
   for (int i = 0; i < 5; i++) putAll(records);
   for (Record record : records)
     assertEquals("Found record does not match put record.", record, this.store.get(record.key()));
 }
Beispiel #6
0
 @Test
 public void testIndexExpansion() throws IOException {
   int numRecords = 3 * this.store.config().indexInitialCapacity();
   List<Record> records = StoreTestUtils.randomRecords(numRecords);
   for (int i = 0; i < numRecords; i++) {
     assertEquals(i, this.store.count());
     assertNull(this.store.put(records.get(i)));
     assertNotNull(this.store.get(records.get(i).key()));
   }
   for (Record record : records) {
     assertEquals("Found record does not match put record.", record, this.store.get(record.key()));
   }
 }
Beispiel #7
0
 @Test
 public void testRecoveryTotalCorruption() throws IOException {
   List<Record> records = StoreTestUtils.randomRecords(10);
   putAll(records);
   // mangle log file
   LogSegment seg = this.store.log().segmentFor(0);
   writeToOffset(seg.file(), 0, "Hayduke lives!".getBytes());
   this.store.close();
   this.store = new HashStore(config);
   if (!config.saveIndexOnClose())
     assertEquals(
         "No records should be present after mangling", Collections.emptyList(), records(store));
 }
Beispiel #8
0
  @Test
  public void testIteration() throws IOException {
    int numRecords = this.store.config().segmentSize();
    List<Record> records = StoreTestUtils.randomRecords(numRecords);
    byte[] key = "hello".getBytes();
    Record old = new Record(key, "world".getBytes());
    records.add(old);
    putAll(records);
    assertEquals("Iteration should give back what we put", records, records(this.store));

    // now update one record and check it is updated in the iterator
    Record newer = new Record(key, "there".getBytes());
    this.store.put(newer);
    records.set(records.size() - 1, newer);
    assertEquals("Iteration should give back what we put", records, records(this.store));
  }