Package com.linkedin.databus.client.pub.FileSystemCheckpointPersistenceProvider

Examples of com.linkedin.databus.client.pub.FileSystemCheckpointPersistenceProvider.CacheEntry


    if (streamFile.exists())
    {
      assertTrue(streamFile.delete());
    }

    CacheEntry cacheEntry = checkpointProvider.new CacheEntry(streamId, null);
    Checkpoint checkpoint = cacheEntry.getCheckpoint();
    assertNull(checkpoint);
  }
View Full Code Here


    //simple checkpoint
    Checkpoint cp1 = new Checkpoint();
    cp1.setFlexible();

    CacheEntry cacheEntry = checkpointProvider.new CacheEntry(streamId, null);
    assertTrue(cacheEntry.setCheckpoint(cp1));
    assertTrue(checkpointFile.exists());

    CacheEntry cacheEntry2 = checkpointProvider.new CacheEntry(streamId, null);
    Checkpoint cp2 = cacheEntry2.getCheckpoint();
    assertNotNull(cp2);
    //TODO need to use a Checkpoint.equals() method
    assertEquals(DbusClientMode.ONLINE_CONSUMPTION, cp2.getConsumptionMode());
    assertTrue(cp2.getFlexible());

    //more complex checkpoint plus overwriting current state
    Checkpoint cp3 = new Checkpoint();
    cp3.setWindowScn(1234L);
    cp3.setWindowOffset(9876);
    cp3.setConsumptionMode(DbusClientMode.ONLINE_CONSUMPTION);

    assertTrue(cacheEntry.setCheckpoint(cp3));
    assertTrue(checkpointFile.exists());

    File cpBackupFile = new File(checkpointDir, streamId + ".oldcurrent");
    assertTrue(cpBackupFile.exists());

    cacheEntry2 = checkpointProvider.new CacheEntry(streamId, null);
    cp2 = cacheEntry2.getCheckpoint();
    assertNotNull(cp2);
    //TODO need to use a Checkpoint.equals() method
    assertEquals(cp3.getConsumptionMode(), cp2.getConsumptionMode());
    assertEquals(cp3.getWindowScn(), cp2.getWindowScn());
    assertEquals(cp3.getPrevScn(), cp2.getPrevScn());
    assertEquals(cp3.getWindowOffset(), cp2.getWindowOffset());

    //make sure the backup still works
    assertTrue(checkpointFile.delete());
    assertTrue(!checkpointFile.exists());

    if (!cpBackupFile.renameTo(checkpointFile))
        LOG.error("file rename failed: " + cpBackupFile.getAbsolutePath() + " --> " +
                  checkpointFile.getAbsolutePath());
    assertTrue(checkpointFile.exists());

    cacheEntry2 = checkpointProvider.new CacheEntry(streamId, null);
    cp2 = cacheEntry2.getCheckpoint();
    assertNotNull(cp2);
    //TODO need to use a Checkpoint.equals() method
    assertEquals(DbusClientMode.ONLINE_CONSUMPTION, cp2.getConsumptionMode());
    assertTrue(cp2.getFlexible());

    //try to keep some stuff around and see if things go south
    Checkpoint cp4 = new Checkpoint();
    cp4.setWindowScn(1111L);
    cp4.setWindowOffset(2222);
    cp4.setConsumptionMode(DbusClientMode.BOOTSTRAP_CATCHUP);

    File newCpFile = new File(checkpointDir, streamId + ".newcheckpoint");
    PrintWriter tmpWriter = new PrintWriter(newCpFile);
    try{
      tmpWriter.println("Dummy");

      assertTrue(cacheEntry.setCheckpoint(cp4));
      assertTrue(checkpointFile.exists());

      cacheEntry2 = checkpointProvider.new CacheEntry(streamId, null);
      cp2 = cacheEntry2.getCheckpoint();
      assertNotNull(cp2);
      //TODO need to use a Checkpoint.equals() method
      assertEquals(cp4.getConsumptionMode(), cp2.getConsumptionMode());
      assertEquals(cp4.getWindowScn(), cp2.getWindowScn());
      assertEquals(cp4.getPrevScn(), cp2.getPrevScn());
View Full Code Here

    }

    Checkpoint[] cp = new Checkpoint[15];

    //store checkpoints
    CacheEntry cacheEntry = checkpointProvider.new CacheEntry(streamId, null);
    for (int i = 0; i < 15; ++i)
    {
      cp[i] = new Checkpoint();
      cp[i].setWindowScn((long)i * i * i);
      cp[i].setWindowOffset(i * i);
      cp[i].setConsumptionMode(DbusClientMode.BOOTSTRAP_SNAPSHOT);

      assertTrue(cacheEntry.setCheckpoint(cp[i]));
      assertTrue(checkpointFile.exists());

      CacheEntry cacheEntry2 = checkpointProvider.new CacheEntry(streamId, null);
      Checkpoint cp2 = cacheEntry2.getCheckpoint();
      assertNotNull(cp2);
      //TODO need to use a Checkpoint.equals() method
      assertEquals(cp[i].getConsumptionMode(), cp2.getConsumptionMode());
      assertEquals(cp[i].getWindowScn(), cp2.getWindowScn());
      assertEquals(cp[i].getPrevScn(), cp2.getPrevScn());
      assertEquals(cp[i].getWindowOffset(), cp2.getWindowOffset());
    }

    //make sure we don't go over history size
    for (int i = 10; i < 15; ++i)
    {
      File f = FileSystemCheckpointPersistenceProvider.StaticConfig.generateCheckpointFile(
          checkpointDir, streamId, i);
      assertTrue(!f.exists());
    }

    //check correctness of history
    for (int i = 0; i < 10; ++i)
    {
      assertTrue(checkpointFile.delete());
      File f = FileSystemCheckpointPersistenceProvider.StaticConfig.generateCheckpointFile(
          checkpointDir, streamId + ".", i);
      assertTrue(f.renameTo(checkpointFile));

      CacheEntry cacheEntry2 = checkpointProvider.new CacheEntry(streamId, null);
      Checkpoint cp2 = cacheEntry2.getCheckpoint();
      assertNotNull(cp2);
      final int j = 13 -i;
      //TODO need to use a Checkpoint.equals() method
      assertEquals(cp[j].getConsumptionMode(), cp2.getConsumptionMode());
      assertEquals(cp[j].getWindowScn(), cp2.getWindowScn());
View Full Code Here

TOP

Related Classes of com.linkedin.databus.client.pub.FileSystemCheckpointPersistenceProvider.CacheEntry

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.