Java Code Examples for org.apache.ratis.statemachine.impl.SimpleStateMachineStorage#getSnapshotFileName()

The following examples show how to use org.apache.ratis.statemachine.impl.SimpleStateMachineStorage#getSnapshotFileName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestRaftStorage.java    From incubator-ratis with Apache License 2.0 6 votes vote down vote up
@Test
public void testSnapshotFileName() throws Exception {
  final long term = ThreadLocalRandom.current().nextLong(Long.MAX_VALUE);
  final long index = ThreadLocalRandom.current().nextLong(Long.MAX_VALUE);
  final String name = SimpleStateMachineStorage.getSnapshotFileName(term, index);
  System.out.println("name = " + name);
  final File file = new File(storageDir, name);
  final TermIndex ti = SimpleStateMachineStorage.getTermIndexFromSnapshotFile(file);
  System.out.println("file = " + file);
  Assert.assertEquals(term, ti.getTerm());
  Assert.assertEquals(index, ti.getIndex());
  System.out.println("ti = " + ti);

  final File foo = new File(storageDir, "foo");
  try {
    SimpleStateMachineStorage.getTermIndexFromSnapshotFile(foo);
    Assert.fail();
  } catch(IllegalArgumentException iae) {
    System.out.println("Good " + iae);
  }
}
 
Example 2
Source File: TestRaftStorage.java    From ratis with Apache License 2.0 6 votes vote down vote up
@Test
public void testSnapshotFileName() throws Exception {
  final long term = ThreadLocalRandom.current().nextLong(Long.MAX_VALUE);
  final long index = ThreadLocalRandom.current().nextLong(Long.MAX_VALUE);
  final String name = SimpleStateMachineStorage.getSnapshotFileName(term, index);
  System.out.println("name = " + name);
  final File file = new File(storageDir, name);
  final TermIndex ti = SimpleStateMachineStorage.getTermIndexFromSnapshotFile(file);
  System.out.println("file = " + file);
  Assert.assertEquals(term, ti.getTerm());
  Assert.assertEquals(index, ti.getIndex());
  System.out.println("ti = " + ti);

  final File foo = new File(storageDir, "foo");
  try {
    SimpleStateMachineStorage.getTermIndexFromSnapshotFile(foo);
    Assert.fail();
  } catch(IllegalArgumentException iae) {
    System.out.println("Good " + iae);
  }
}