Search in sources :

Example 1 with GridAbsClosureX

use of org.apache.ignite.internal.util.lang.GridAbsClosureX 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 GridAbsClosureX

use of org.apache.ignite.internal.util.lang.GridAbsClosureX 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 3 with GridAbsClosureX

use of org.apache.ignite.internal.util.lang.GridAbsClosureX 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)

Example 4 with GridAbsClosureX

use of org.apache.ignite.internal.util.lang.GridAbsClosureX in project ignite by apache.

the class GridTaskExecutionContextSelfTest method testWithNoFailoverClosure.

/**
     * @throws Exception If failed.
     */
public void testWithNoFailoverClosure() throws Exception {
    final IgniteRunnable r = new GridAbsClosureX() {

        @Override
        public void applyx() {
            CNT.incrementAndGet();
            throw new ComputeExecutionRejectedException("Expected error.");
        }
    };
    final Ignite g = grid(0);
    GridTestUtils.assertThrows(log, new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            g.compute().withNoFailover().run(r);
            return null;
        }
    }, ComputeExecutionRejectedException.class, "Expected error.");
    assertEquals(1, CNT.get());
}
Also used : ComputeExecutionRejectedException(org.apache.ignite.compute.ComputeExecutionRejectedException) Ignite(org.apache.ignite.Ignite) GridAbsClosureX(org.apache.ignite.internal.util.lang.GridAbsClosureX) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) ComputeExecutionRejectedException(org.apache.ignite.compute.ComputeExecutionRejectedException)

Aggregations

GridAbsClosureX (org.apache.ignite.internal.util.lang.GridAbsClosureX)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 GridCheckpointTestState (org.apache.ignite.spi.checkpoint.GridCheckpointTestState)3 IgniteIgnore (org.apache.ignite.testsuites.IgniteIgnore)3 Ignite (org.apache.ignite.Ignite)1 ComputeExecutionRejectedException (org.apache.ignite.compute.ComputeExecutionRejectedException)1 IgniteRunnable (org.apache.ignite.lang.IgniteRunnable)1