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()));
}
}
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"));
}
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());
}
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()));
}
}
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());
}
Aggregations