Search in sources :

Example 46 with IgniteDataStreamer

use of org.apache.ignite.IgniteDataStreamer in project ignite by apache.

the class LazyOnDmlTest method beforeTest.

/**
 * {@inheritDoc}
 */
@Override
protected void beforeTest() throws Exception {
    super.beforeTest();
    IgniteCache<Long, Long> c = grid(0).createCache(new CacheConfiguration<Long, Long>().setName("test").setSqlSchema("TEST").setAtomicityMode(atomicityMode).setCacheMode(cacheMode).setQueryEntities(Collections.singleton(new QueryEntity(Long.class.getName(), "testVal").setTableName("test").addQueryField("id", Long.class.getName(), null).addQueryField("val0", Long.class.getName(), null).addQueryField("val1", Long.class.getName(), null).addQueryField("val2", Long.class.getName(), null).setKeyFieldName("id").setIndexes(Collections.singletonList(new QueryIndex(Arrays.asList("val0", "val1"), QueryIndexType.SORTED))))).setBackups(1).setAffinity(new RendezvousAffinityFunction(false, 10)));
    try (IgniteDataStreamer streamer = grid(0).dataStreamer("test")) {
        for (long i = 0; i < KEY_CNT; ++i) {
            BinaryObjectBuilder bob = grid(0).binary().builder("testVal");
            bob.setField("val0", i);
            bob.setField("val1", i);
            bob.setField("val2", i);
            streamer.addData(i, bob.build());
        }
    }
    sql("CREATE TABLE table1 (id INT PRIMARY KEY, col0 INT, col1 VARCHAR (100))");
    sql("INSERT INTO table1 (id, col0, col1) " + "SELECT 1, 11, 'FIRST' " + "UNION ALL " + "SELECT 11,12, 'SECOND' " + "UNION ALL " + "SELECT 21, 13, 'THIRD' " + "UNION ALL " + "SELECT 31, 14, 'FOURTH'");
    sql("CREATE TABLE  table2 (id INT PRIMARY KEY, col0 INT, col1 VARCHAR (100))");
    sql("INSERT INTO table2 (id, col0, col1) " + "SELECT 1, 21, 'TWO-ONE' " + "UNION ALL " + "SELECT 11, 22, 'TWO-TWO' " + "UNION ALL " + "SELECT 21, 23, 'TWO-THREE' " + "UNION ALL " + "SELECT 31, 24, 'TWO-FOUR'");
}
Also used : IgniteDataStreamer(org.apache.ignite.IgniteDataStreamer) QueryIndex(org.apache.ignite.cache.QueryIndex) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) QueryEntity(org.apache.ignite.cache.QueryEntity) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 47 with IgniteDataStreamer

use of org.apache.ignite.IgniteDataStreamer in project ignite by apache.

the class GridInternalTaskUnusedWalSegmentsTest method testCorrectnessOfDeletionTaskSegments.

/**
 * Tests correctness of {@link VisorWalTaskOperation}.
 *
 * @throws Exception if failed.
 */
@Test
@WithSystemProperty(key = IGNITE_PDS_MAX_CHECKPOINT_MEMORY_HISTORY_SIZE, value = "2")
public void testCorrectnessOfDeletionTaskSegments() throws Exception {
    try {
        IgniteEx ig0 = (IgniteEx) startGrids(4);
        ig0.cluster().active(true);
        try (IgniteDataStreamer streamer = ig0.dataStreamer(DEFAULT_CACHE_NAME)) {
            for (int k = 0; k < 10_000; k++) streamer.addData(k, new byte[1024]);
        }
        forceCheckpoint();
        try (IgniteDataStreamer streamer = ig0.dataStreamer(DEFAULT_CACHE_NAME)) {
            for (int k = 0; k < 1_000; k++) streamer.addData(k, new byte[1024]);
        }
        forceCheckpoint();
        VisorWalTaskResult printRes = ig0.compute().execute(VisorWalTask.class, new VisorTaskArgument<>(ig0.cluster().node().id(), new VisorWalTaskArg(VisorWalTaskOperation.PRINT_UNUSED_WAL_SEGMENTS), false));
        assertEquals("Check that print task finished without exceptions", printRes.results().size(), 4);
        List<File> walArchives = new ArrayList<>();
        for (Collection<String> pathsPerNode : printRes.results().values()) {
            for (String path : pathsPerNode) walArchives.add(Paths.get(path).toFile());
        }
        VisorWalTaskResult delRes = ig0.compute().execute(VisorWalTask.class, new VisorTaskArgument<>(ig0.cluster().node().id(), new VisorWalTaskArg(VisorWalTaskOperation.DELETE_UNUSED_WAL_SEGMENTS), false));
        assertEquals("Check that delete task finished with no exceptions", delRes.results().size(), 4);
        List<File> walDeletedArchives = new ArrayList<>();
        for (Collection<String> pathsPerNode : delRes.results().values()) {
            for (String path : pathsPerNode) walDeletedArchives.add(Paths.get(path).toFile());
        }
        for (File f : walDeletedArchives) assertTrue("Checking existing of deleted WAL archived segments: " + f.getAbsolutePath(), !f.exists());
        for (File f : walArchives) assertTrue("Checking existing of WAL archived segments from print task after delete: " + f.getAbsolutePath(), !f.exists());
    } finally {
        stopAllGrids();
    }
}
Also used : VisorWalTaskArg(org.apache.ignite.internal.visor.misc.VisorWalTaskArg) IgniteDataStreamer(org.apache.ignite.IgniteDataStreamer) IgniteEx(org.apache.ignite.internal.IgniteEx) VisorWalTaskResult(org.apache.ignite.internal.visor.misc.VisorWalTaskResult) ArrayList(java.util.ArrayList) File(java.io.File) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty)

Aggregations

IgniteDataStreamer (org.apache.ignite.IgniteDataStreamer)47 Ignite (org.apache.ignite.Ignite)25 Test (org.junit.Test)21 IgniteCache (org.apache.ignite.IgniteCache)19 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)18 IgniteEx (org.apache.ignite.internal.IgniteEx)16 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)14 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)10 List (java.util.List)8 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)8 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)8 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)8 Ignition (org.apache.ignite.Ignition)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 Random (java.util.Random)6 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)6 UUID (java.util.UUID)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5