Search in sources :

Example 1 with DialogOptional

use of org.tron.common.utils.DialogOptional in project java-tron by tronprotocol.

the class RevokingStoreTest method testUndo.

@Test
public synchronized void testUndo() {
    revokingDatabase.getStack().clear();
    TestRevokingTronStore tronDatabase = new TestRevokingTronStore("testrevokingtronstore-testUndo", revokingDatabase);
    TestProtoCapsule testProtoCapsule = new TestProtoCapsule();
    DialogOptional dialog = DialogOptional.of(revokingDatabase.buildDialog());
    IntStream.range(0, 10).forEach(i -> {
        try (Dialog tmpDialog = revokingDatabase.buildDialog()) {
            tronDatabase.put(testProtoCapsule.getData(), testProtoCapsule);
            Assert.assertFalse(tronDatabase.getDbSource().allKeys().isEmpty());
            Assert.assertEquals(revokingDatabase.getStack().size(), 2);
            tmpDialog.merge();
            Assert.assertEquals(revokingDatabase.getStack().size(), 1);
        } catch (RevokingStoreIllegalStateException e) {
            logger.debug(e.getMessage(), e);
        }
    });
    Assert.assertEquals(revokingDatabase.getStack().size(), 1);
    dialog.reset();
    Assert.assertTrue(revokingDatabase.getStack().isEmpty());
    Assert.assertTrue(tronDatabase.getDbSource().allKeys().isEmpty());
    Assert.assertEquals(revokingDatabase.getActiveDialog(), 0);
    tronDatabase.close();
}
Also used : Dialog(org.tron.core.db.AbstractRevokingStore.Dialog) DialogOptional(org.tron.common.utils.DialogOptional) RevokingStoreIllegalStateException(org.tron.core.exception.RevokingStoreIllegalStateException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 DialogOptional (org.tron.common.utils.DialogOptional)1 Dialog (org.tron.core.db.AbstractRevokingStore.Dialog)1 RevokingStoreIllegalStateException (org.tron.core.exception.RevokingStoreIllegalStateException)1