Search in sources :

Example 1 with Buffer

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

the class EngineTest method testNoDuplicateDataIfUnexpectedShutdownOccurs.

@Test
public void testNoDuplicateDataIfUnexpectedShutdownOccurs() throws Exception {
    Engine engine = (Engine) store;
    Buffer buffer = (Buffer) engine.limbo;
    // (authorized)
    Reflection.set("transportRateMultiplier", 1, buffer);
    Database db = (Database) engine.durable;
    Method method = buffer.getClass().getDeclaredMethod("canTransport");
    method.setAccessible(true);
    int count = 0;
    while (!(boolean) method.invoke(buffer)) {
        engine.add("count", Convert.javaToThrift(count), Integer.valueOf(count).longValue());
        count++;
    }
    for (int i = 0; i < count - 2; i++) {
        // leave one write on the page so
        // buffer doesn't automatically
        // call db.triggerSync()
        buffer.transport(db);
    }
    db.sync();
    engine = new Engine(buffer.getBackingStore(), db.getBackingStore());
    // Simulate unexpected shutdown by "restarting" the
    engine.start();
    // Engine
    while ((boolean) method.invoke(engine.limbo)) {
        // wait until the first
        // page in the buffer
        // (which contains the
        // same data that was
        // previously
        // transported) is done
        // transporting again
        Random.sleep();
    }
    for (int i = 0; i < count; i++) {
        Assert.assertTrue(engine.find("count", Operator.EQUALS, Convert.javaToThrift(i)).contains(Integer.valueOf(i).longValue()));
    }
}
Also used : Buffer(com.cinchapi.concourse.server.storage.temp.Buffer) Database(com.cinchapi.concourse.server.storage.db.Database) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 2 with Buffer

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

the class EngineTest method testReproGH_442.

@Test
public void testReproGH_442() throws Exception {
    // Unexpected shutdown should not allow consecutive Writes that are not
    // properly offset
    Engine engine = (Engine) store;
    Buffer buffer = (Buffer) engine.limbo;
    Database db = (Database) engine.durable;
    Method method = buffer.getClass().getDeclaredMethod("canTransport");
    method.setAccessible(true);
    buffer.insert(Write.add("name", Convert.javaToThrift("jeff"), 1));
    buffer.insert(Write.remove("name", Convert.javaToThrift("jeff"), 1));
    buffer.insert(Write.add("name", Convert.javaToThrift("jeff"), 2));
    buffer.insert(Write.remove("name", Convert.javaToThrift("jeff"), 2));
    buffer.insert(Write.add("name", Convert.javaToThrift("jeff"), 2));
    while (!(boolean) method.invoke(buffer)) {
        // Fill the page so the
        // buffer can transport
        engine.add("count", Convert.javaToThrift(Time.now()), Time.now());
    }
    for (int i = 0; i < 4; ++i) {
        buffer.transport(db);
    }
    db.sync();
    engine = new Engine(buffer.getBackingStore(), db.getBackingStore());
    // Simulate unexpected shutdown by "restarting" the
    engine.start();
    // Engine
    while ((boolean) method.invoke(engine.limbo)) {
        // wait until the first
        // page in the buffer
        // (which contains the
        // same data that was
        // previously
        // transported) is done
        // transporting again
        Random.sleep();
    }
    engine.find("name", Operator.EQUALS, Convert.javaToThrift("jeff"));
}
Also used : Buffer(com.cinchapi.concourse.server.storage.temp.Buffer) Database(com.cinchapi.concourse.server.storage.db.Database) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 3 with Buffer

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

the class EngineTest method testSameWriteVersionDatabaseIntersectionDetection.

@Test
public void testSameWriteVersionDatabaseIntersectionDetection() {
    Engine engine = (Engine) store;
    Buffer buffer = (Buffer) engine.limbo;
    Database db = (Database) engine.durable;
    int count = TestData.getScaleCount();
    AtomicLong commits = new AtomicLong();
    AtomicLong expected = new AtomicLong();
    for (int i = 0; i < count; ++i) {
        AtomicOperation atomic = engine.startAtomicOperation();
        int writes = TestData.getScaleCount();
        for (int j = 0; j < writes; ++j) {
            atomic.add("name", Convert.javaToThrift("jeff" + i), Math.abs(TestData.getInt()) % 2 == 0 ? Time.now() : j);
            expected.incrementAndGet();
        }
        atomic.commit();
        commits.incrementAndGet();
    }
    while (Reflection.<Boolean>call(buffer, "canTransport")) {
        buffer.transport(db);
    }
    Set<Long> versions = new HashSet<>();
    AtomicLong actual = new AtomicLong();
    Iterator<Write> it = db.iterator();
    while (it.hasNext()) {
        versions.add(it.next().getVersion());
        actual.incrementAndGet();
    }
    it = buffer.iterator();
    while (it.hasNext()) {
        versions.add(it.next().getVersion());
        actual.incrementAndGet();
    }
    Assert.assertEquals(commits.get(), versions.size());
    Assert.assertEquals(expected.get(), actual.get());
    engine.stop();
    engine.start();
    buffer = (Buffer) engine.limbo;
    db = (Database) engine.durable;
    versions.clear();
    actual = new AtomicLong(0);
    it = db.iterator();
    while (it.hasNext()) {
        Write write = it.next();
        versions.add(write.getVersion());
        actual.incrementAndGet();
    }
    it = buffer.iterator();
    while (it.hasNext()) {
        Write write = it.next();
        versions.add(write.getVersion());
        actual.incrementAndGet();
    }
    Assert.assertEquals(commits.get(), versions.size());
    Assert.assertEquals(expected.get(), actual.get());
}
Also used : Buffer(com.cinchapi.concourse.server.storage.temp.Buffer) Write(com.cinchapi.concourse.server.storage.temp.Write) AtomicLong(java.util.concurrent.atomic.AtomicLong) Database(com.cinchapi.concourse.server.storage.db.Database) AtomicLong(java.util.concurrent.atomic.AtomicLong) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with Buffer

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

the class EngineTest method testReproGH_441.

@Test
public void testReproGH_441() throws Exception {
    // Unexpected shutdown should not allow duplicate Write versions to by
    // transferred
    Engine engine = (Engine) store;
    Buffer buffer = (Buffer) engine.limbo;
    Database db = (Database) engine.durable;
    Method method = buffer.getClass().getDeclaredMethod("canTransport");
    method.setAccessible(true);
    buffer.insert(Write.add("name", Convert.javaToThrift("jeff"), 1));
    buffer.insert(Write.add("name", Convert.javaToThrift("jeff"), 2));
    buffer.insert(Write.remove("name", Convert.javaToThrift("jeff"), 2));
    buffer.insert(Write.add("name", Convert.javaToThrift("jeff"), 2));
    buffer.insert(Write.remove("name", Convert.javaToThrift("jeff"), 2));
    while (!(boolean) method.invoke(buffer)) {
        // Fill the page so the
        // buffer can transport
        engine.add("count", Convert.javaToThrift(Time.now()), Time.now());
    }
    for (int i = 0; i < 6; ++i) {
        buffer.transport(db);
    }
    db.sync();
    engine.stop();
    engine = new Engine(buffer.getBackingStore(), db.getBackingStore());
    // Simulate unexpected shutdown by "restarting" the
    engine.start();
    // Engine
    db = (Database) engine.durable;
    while ((boolean) method.invoke(engine.limbo)) {
        // wait until the first
        // page in the buffer
        // (which contains the
        // same data that was
        // previously
        // transported) is done
        // transporting again
        Random.sleep();
    }
    Iterator<Write> it = db.iterator();
    Set<Long> versions = new HashSet<>();
    while (it.hasNext()) {
        Assert.assertTrue(versions.add(it.next().getVersion()));
    }
}
Also used : Buffer(com.cinchapi.concourse.server.storage.temp.Buffer) Write(com.cinchapi.concourse.server.storage.temp.Write) Database(com.cinchapi.concourse.server.storage.db.Database) AtomicLong(java.util.concurrent.atomic.AtomicLong) Method(java.lang.reflect.Method) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with Buffer

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

the class EngineTest method reproCON_516.

@Test
public void reproCON_516() {
    Engine engine = (Engine) store;
    Buffer buffer = (Buffer) engine.limbo;
    int count = 0;
    while (!(boolean) Reflection.call(buffer, "canTransport")) {
        add("name", Convert.javaToThrift("Jeff"), Time.now());
        count++;
    }
    buffer.transport(engine.durable);
    add("name", Convert.javaToThrift("Jeff"), Time.now());
    count++;
    Set<Long> matches = engine.find("name", Operator.EQUALS, Convert.javaToThrift("jeff"));
    Assert.assertEquals(count, matches.size());
}
Also used : Buffer(com.cinchapi.concourse.server.storage.temp.Buffer) AtomicLong(java.util.concurrent.atomic.AtomicLong) Test(org.junit.Test)

Aggregations

Buffer (com.cinchapi.concourse.server.storage.temp.Buffer)6 Test (org.junit.Test)6 Database (com.cinchapi.concourse.server.storage.db.Database)5 Write (com.cinchapi.concourse.server.storage.temp.Write)3 Method (java.lang.reflect.Method)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 HashSet (java.util.HashSet)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1