Search in sources :

Example 16 with Write

use of com.cinchapi.concourse.server.storage.temp.Write in project concourse by cinchapi.

the class DatabaseTest method testRepairDuplicateData.

@Test
public void testRepairDuplicateData() {
    Database db = (Database) store;
    Set<Write> duplicates = Sets.newHashSet();
    for (int i = 0; i < 10; ++i) {
        duplicates.add(Write.add(TestData.getSimpleString(), TestData.getTObject(), TestData.getIdentifier().longValue()));
    }
    for (Write write : duplicates) {
        db.accept(write);
    }
    db.sync();
    Write duplicate = null;
    int count = 0;
    while (count < 5 || duplicate == null) {
        boolean addDuplicates = TestData.getScaleCount() % 3 == 0;
        for (int j = 0; j < TestData.getScaleCount(); ++j) {
            Write write = null;
            if (addDuplicates && TestData.getScaleCount() % 5 == 0) {
                write = Iterables.get(duplicates, Math.abs(TestData.getInt()) % duplicates.size());
                duplicate = MoreObjects.firstNonNull(duplicate, write);
            } else {
                while (write == null || duplicates.contains(write)) {
                    write = TestData.getWriteAdd();
                }
            }
            db.accept(write);
        }
        db.sync();
        ++count;
    }
    Write write = duplicate;
    try {
        db.verify(write.getKey().toString(), write.getValue().getTObject(), write.getRecord().longValue());
        Assert.fail("Expected an unoffset Write exception");
    } catch (Exception e) {
        Assert.assertTrue(true);
    }
    try {
        db.select(write.getRecord().longValue());
        Assert.fail("Expected an unoffset Write exception");
    } catch (Exception e) {
        Assert.assertTrue(true);
    }
    db.repair();
    db.verify(write.getKey().toString(), write.getValue().getTObject(), write.getRecord().longValue());
    db.select(write.getRecord().longValue());
}
Also used : Write(com.cinchapi.concourse.server.storage.temp.Write) StoreTest(com.cinchapi.concourse.server.storage.StoreTest) Test(org.junit.Test)

Aggregations

Write (com.cinchapi.concourse.server.storage.temp.Write)16 Test (org.junit.Test)13 Identifier (com.cinchapi.concourse.server.model.Identifier)5 ConcourseBaseTest (com.cinchapi.concourse.test.ConcourseBaseTest)5 Text (com.cinchapi.concourse.server.model.Text)4 StoreTest (com.cinchapi.concourse.server.storage.StoreTest)4 Database (com.cinchapi.concourse.server.storage.db.Database)4 TObject (com.cinchapi.concourse.thrift.TObject)4 Buffer (com.cinchapi.concourse.server.storage.temp.Buffer)3 Value (com.cinchapi.concourse.server.model.Value)2 Segment (com.cinchapi.concourse.server.storage.db.kernel.Segment)2 Convert (com.cinchapi.concourse.util.Convert)2 TestData (com.cinchapi.concourse.util.TestData)2 Path (java.nio.file.Path)2 Paths (java.nio.file.Paths)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Set (java.util.Set)2 ExecutorService (java.util.concurrent.ExecutorService)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2