Search in sources :

Example 1 with GridCheckpointTestState

use of org.apache.ignite.spi.checkpoint.GridCheckpointTestState in project ignite by apache.

the class S3CheckpointSpiSelfTest method testSaveWithExpire.

/**
     * @throws Exception Thrown in case of any errors.
     */
@IgniteIgnore("https://issues.apache.org/jira/browse/IGNITE-2420")
public void testSaveWithExpire() throws Exception {
    // Save states.
    for (int i = 0; i < CHECK_POINT_COUNT; i++) {
        GridCheckpointTestState state = new GridCheckpointTestState("Test check point data " + i + '.');
        getSpi().saveCheckpoint(KEY_PREFIX + i, GridTestIoUtils.serializeJdk(state), 1, true);
    }
    // For small expiration intervals no warranty that state will be removed.
    Thread.sleep(100);
    // Check that states was removed.
    for (int i = 0; i < CHECK_POINT_COUNT; i++) {
        final String key = KEY_PREFIX + i;
        assertWithRetries(new GridAbsClosureX() {

            @Override
            public void applyx() throws IgniteCheckedException {
                assertNull("Checkpoint state should not be loaded with key: " + key, getSpi().loadCheckpoint(key));
            }
        });
    }
}
Also used : GridCheckpointTestState(org.apache.ignite.spi.checkpoint.GridCheckpointTestState) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridAbsClosureX(org.apache.ignite.internal.util.lang.GridAbsClosureX) IgniteIgnore(org.apache.ignite.testsuites.IgniteIgnore)

Example 2 with GridCheckpointTestState

use of org.apache.ignite.spi.checkpoint.GridCheckpointTestState in project ignite by apache.

the class GridSharedFsCheckpointSpiMultipleDirectoriesSelfTest method testMultipleSharedDirectories.

/**
     * @throws Exception If failed.
     */
public void testMultipleSharedDirectories() throws Exception {
    String data = "Test check point data.";
    GridCheckpointTestState state = new GridCheckpointTestState(data);
    getSpi().saveCheckpoint(CHECK_POINT_KEY_PREFIX, GridTestIoUtils.serializeJdk(state), 0, true);
    info("Saved check point [key=" + CHECK_POINT_KEY_PREFIX + ", data=" + state + ']');
    String curSpiPath1 = getSpi().getCurrentDirectoryPath();
    File folder1 = U.resolveWorkDirectory(U.defaultWorkDirectory(), curSpiPath1, false);
    assert folder1.exists() : "Checkpoint folder doesn't exist.";
    boolean rewritten = getSpi().saveCheckpoint(CHECK_POINT_KEY_PREFIX, GridTestIoUtils.serializeJdk(state), 0, true);
    assert rewritten : "Check point was not rewritten.";
    info("Rewrite check point [key=" + CHECK_POINT_KEY_PREFIX + ", data=" + state + ']');
    String curSpiPath2 = getSpi().getCurrentDirectoryPath();
    File folder2 = U.resolveWorkDirectory(U.defaultWorkDirectory(), curSpiPath2, false);
    assert folder2.exists() : "Check point folder doesn't exist.";
    assert folder1.getAbsoluteFile().equals(folder2.getAbsoluteFile()) : "folder1 should be equal folder2.";
    U.delete(folder2);
    getSpi().saveCheckpoint(CHECK_POINT_KEY_PREFIX, GridTestIoUtils.serializeJdk(state), 0, true);
    info("Saved check point to other folder [key=" + CHECK_POINT_KEY_PREFIX + ", data=" + state + ']');
    String newCurSpiPath = getSpi().getCurrentDirectoryPath();
    File changedFolder = U.resolveWorkDirectory(U.defaultWorkDirectory(), newCurSpiPath, false);
    assert changedFolder.exists() : "Check point folder doesn't exist.";
    assert !folder2.getAbsolutePath().equals(changedFolder.getAbsolutePath()) : "Directories should not be equal.";
    U.delete(changedFolder);
    boolean error = false;
    // Try save after delete all directories.
    try {
        getSpi().saveCheckpoint(CHECK_POINT_KEY_PREFIX, GridTestIoUtils.serializeJdk(state), 0, true);
    } catch (IgniteException ignored) {
        error = true;
    }
    assert error : "Check point should not be saved.";
}
Also used : GridCheckpointTestState(org.apache.ignite.spi.checkpoint.GridCheckpointTestState) IgniteException(org.apache.ignite.IgniteException) File(java.io.File)

Example 3 with GridCheckpointTestState

use of org.apache.ignite.spi.checkpoint.GridCheckpointTestState in project ignite by apache.

the class S3CheckpointSpiSelfTest method testSaveLoadRemoveWithoutExpire.

/**
     * @throws Exception Thrown in case of any errors.
     */
@IgniteIgnore("https://issues.apache.org/jira/browse/IGNITE-2420")
public void testSaveLoadRemoveWithoutExpire() throws Exception {
    String dataPrefix = "Test check point data ";
    // Save states.
    for (int i = 0; i < CHECK_POINT_COUNT; i++) {
        GridCheckpointTestState state = new GridCheckpointTestState(dataPrefix + i);
        getSpi().saveCheckpoint(KEY_PREFIX + i, GridTestIoUtils.serializeJdk(state), 0, true);
    }
    // Load and check states.
    for (int i = 0; i < CHECK_POINT_COUNT; i++) {
        final String key = KEY_PREFIX + i;
        assertWithRetries(new GridAbsClosureX() {

            @Override
            public void applyx() throws IgniteCheckedException {
                assertNotNull("Missing checkpoint: " + key, getSpi().loadCheckpoint(key));
            }
        });
        // Doing it again as pulling value from repeated assertion is tricky,
        // and all assertions below shouldn't be retried in case of failure.
        byte[] serState = getSpi().loadCheckpoint(key);
        GridCheckpointTestState state = GridTestIoUtils.deserializeJdk(serState);
        assertNotNull("Can't load checkpoint state for key: " + key, state);
        assertEquals("Invalid state loaded [expected='" + dataPrefix + i + "', received='" + state.getData() + "']", dataPrefix + i, state.getData());
    }
    // Remove states.
    for (int i = 0; i < CHECK_POINT_COUNT; i++) {
        final String key = KEY_PREFIX + i;
        assertWithRetries(new GridAbsClosureX() {

            @Override
            public void applyx() throws IgniteCheckedException {
                assertTrue(getSpi().removeCheckpoint(key));
            }
        });
    }
    // Check that states was removed.
    for (int i = 0; i < CHECK_POINT_COUNT; i++) {
        final String key = KEY_PREFIX + i;
        assertWithRetries(new GridAbsClosureX() {

            @Override
            public void applyx() throws IgniteCheckedException {
                assertNull(getSpi().loadCheckpoint(key));
            }
        });
    }
}
Also used : GridCheckpointTestState(org.apache.ignite.spi.checkpoint.GridCheckpointTestState) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridAbsClosureX(org.apache.ignite.internal.util.lang.GridAbsClosureX) IgniteIgnore(org.apache.ignite.testsuites.IgniteIgnore)

Example 4 with GridCheckpointTestState

use of org.apache.ignite.spi.checkpoint.GridCheckpointTestState in project ignite by apache.

the class S3CheckpointSpiSelfTest method testDuplicates.

/**
     * @throws Exception Thrown in case of any errors.
     */
@IgniteIgnore("https://issues.apache.org/jira/browse/IGNITE-2420")
public void testDuplicates() throws Exception {
    int idx1 = 1;
    int idx2 = 2;
    GridCheckpointTestState state1 = new GridCheckpointTestState(Integer.toString(idx1));
    GridCheckpointTestState state2 = new GridCheckpointTestState(Integer.toString(idx2));
    getSpi().saveCheckpoint(KEY_PREFIX, GridTestIoUtils.serializeJdk(state1), 0, true);
    getSpi().saveCheckpoint(KEY_PREFIX, GridTestIoUtils.serializeJdk(state2), 0, true);
    assertWithRetries(new GridAbsClosureX() {

        @Override
        public void applyx() throws IgniteCheckedException {
            assertNotNull(getSpi().loadCheckpoint(KEY_PREFIX));
        }
    });
    byte[] serState = getSpi().loadCheckpoint(KEY_PREFIX);
    GridCheckpointTestState state = GridTestIoUtils.deserializeJdk(serState);
    assertNotNull(state);
    assertEquals(state2, state);
    // Remove.
    getSpi().removeCheckpoint(KEY_PREFIX);
    assertWithRetries(new GridAbsClosureX() {

        @Override
        public void applyx() throws IgniteCheckedException {
            assertNull(getSpi().loadCheckpoint(KEY_PREFIX));
        }
    });
}
Also used : GridCheckpointTestState(org.apache.ignite.spi.checkpoint.GridCheckpointTestState) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridAbsClosureX(org.apache.ignite.internal.util.lang.GridAbsClosureX) IgniteIgnore(org.apache.ignite.testsuites.IgniteIgnore)

Aggregations

GridCheckpointTestState (org.apache.ignite.spi.checkpoint.GridCheckpointTestState)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 GridAbsClosureX (org.apache.ignite.internal.util.lang.GridAbsClosureX)3 IgniteIgnore (org.apache.ignite.testsuites.IgniteIgnore)3 File (java.io.File)1 IgniteException (org.apache.ignite.IgniteException)1