示例#1
0
 @Test
 public void testBufferTransportBlockingIfWritesAreNotWithinThreshold() {
   String loc = TestData.DATA_DIR + File.separator + Time.now();
   final Engine engine = new Engine(loc + File.separator + "buffer", loc + File.separator + "db");
   engine.start();
   engine.add(TestData.getString(), TestData.getTObject(), TestData.getLong());
   Threads.sleep(
       Engine.BUFFER_TRANSPORT_THREAD_ALLOWABLE_INACTIVITY_THRESHOLD_IN_MILLISECONDS + 10);
   engine.add(TestData.getString(), TestData.getTObject(), TestData.getLong());
   Assert.assertTrue(engine.bufferTransportThreadHasEverPaused.get());
   engine.stop();
   FileSystem.deleteDirectory(loc);
 }
示例#2
0
  @Test
  public void reproCON_239AuditRecord() throws InterruptedException {
    final Engine engine = (Engine) store;
    int count = TestData.getScaleCount();
    for (int i = 0; i < count; i++) {
      engine.add(Long.toString(Time.now()), Convert.javaToThrift(i), 1);
    }
    engine.add("foo", Convert.javaToThrift("a"), 1);
    final AtomicBoolean done = new AtomicBoolean(false);
    final AtomicBoolean go = new AtomicBoolean(false);
    Thread write =
        new Thread(
            new Runnable() {

              @Override
              public void run() {
                while (!go.get()) {
                  continue; // ensure read goes first
                }
                while (!done.get()) {
                  if (!done.get()) {
                    engine.add("foo", Convert.javaToThrift(Long.toString(Time.now())), 1);
                  }
                }
              }
            });
    final AtomicBoolean succeeded = new AtomicBoolean(true);
    Thread read =
        new Thread(
            new Runnable() {

              @Override
              public void run() {
                go.set(true);
                Map<Long, String> data = engine.audit(1);
                done.set(true);
                Map<Long, String> data1 = engine.audit(1);
                Variables.register("data_size", data.size());
                Variables.register("data1_size", data1.size());
                succeeded.set(data.size() == data1.size() || data.size() == data1.size() - 1);
              }
            });

    read.start();
    write.start();
    read.join();
    write.join();
    Assert.assertTrue(succeeded.get());
  }
示例#3
0
 @Test
 public void testNoBufferTransportBlockingIfWritesAreWithinThreshold() {
   String loc = TestData.DATA_DIR + File.separator + Time.now();
   final Engine engine = new Engine(loc + File.separator + "buffer", loc + File.separator + "db");
   Variables.register("now", Time.now());
   engine.start();
   engine.add(TestData.getString(), TestData.getTObject(), TestData.getLong());
   engine.add(TestData.getString(), TestData.getTObject(), TestData.getLong());
   engine.stop();
   Assert.assertFalse(engine.bufferTransportThreadHasEverPaused.get());
   FileSystem.deleteDirectory(loc);
 }
示例#4
0
 @Test
 public void testNoDuplicateDataIfUnexpectedShutdownOccurs() throws Exception {
   Engine engine = (Engine) store;
   Buffer buffer = (Buffer) engine.buffer;
   Database db = (Database) engine.destination;
   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.triggerSync();
   engine = new Engine(buffer.getBackingStore(), db.getBackingStore());
   engine.start(); // Simulate unexpected shutdown by "restarting" the
   // Engine
   while ((boolean) method.invoke(engine.buffer)) { // 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()));
   }
 }
示例#5
0
 @Override
 protected void add(String key, TObject value, long record) {
   ((Engine) store).add(key, value, record);
 }