Search in sources :

Example 16 with GridLongList

use of org.apache.ignite.internal.util.GridLongList in project ignite by apache.

the class GridLongListSelfTest method testSerializationConstructorWithZeroSize.

/**
 */
@Ignore("https://issues.apache.org/jira/browse/IGNITE-12678")
@Test
public void testSerializationConstructorWithZeroSize() {
    MessageWriter writer = new DirectMessageWriter(GridIoManager.DIRECT_PROTO_VER);
    ByteBuffer buf = ByteBuffer.allocate(4096);
    GridLongList ll = new GridLongList(0);
    {
        Assert.assertTrue(ll.writeTo(buf, writer));
        Assert.assertEquals(HEADER_SIZE + 1 + /* array */
        1, /* index */
        buf.position());
    }
    {
        writer.reset();
        buf.clear();
        ll.add(2L);
        ll.add(4L);
        Assert.assertTrue(ll.writeTo(buf, writer));
        Assert.assertEquals(HEADER_SIZE + 17 + /* array */
        1, /* index */
        buf.position());
    }
    {
        writer.reset();
        buf.clear();
        ll.remove();
        Assert.assertTrue(ll.writeTo(buf, writer));
        Assert.assertEquals(HEADER_SIZE + 9 + /* array */
        1, /* index */
        buf.position());
    }
    {
        writer.reset();
        buf.clear();
        ll.remove();
        Assert.assertTrue(ll.writeTo(buf, writer));
        Assert.assertEquals(HEADER_SIZE + 1 + /* array */
        1, /* index */
        buf.position());
    }
    {
        writer.reset();
        buf.clear();
        for (int i = 0; i < 300; i++) ll.add(i);
        Assert.assertTrue(ll.writeTo(buf, writer));
        Assert.assertEquals(300, ll.size());
        Assert.assertEquals(HEADER_SIZE + 2402 + /* array */
        2, /* index */
        buf.position());
    }
    {
        writer.reset();
        buf.clear();
        ll.clear();
        Assert.assertTrue(ll.writeTo(buf, writer));
        Assert.assertEquals(HEADER_SIZE + 1 + /* array */
        1, /* index */
        buf.position());
    }
}
Also used : DirectMessageWriter(org.apache.ignite.internal.direct.DirectMessageWriter) GridLongList(org.apache.ignite.internal.util.GridLongList) DirectMessageWriter(org.apache.ignite.internal.direct.DirectMessageWriter) MessageWriter(org.apache.ignite.plugin.extensions.communication.MessageWriter) ByteBuffer(java.nio.ByteBuffer) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 17 with GridLongList

use of org.apache.ignite.internal.util.GridLongList in project ignite by apache.

the class GridLongListSelfTest method testSort.

/**
 */
@Test
public void testSort() {
    assertEquals(new GridLongList(), new GridLongList().sort());
    assertEquals(asList(1), asList(1).sort());
    assertEquals(asList(1, 2), asList(2, 1).sort());
    assertEquals(asList(1, 2, 3), asList(2, 1, 3).sort());
    GridLongList list = new GridLongList();
    list.add(4);
    list.add(3);
    list.add(5);
    list.add(1);
    assertEquals(asList(1, 3, 4, 5), list.sort());
    list.add(0);
    assertEquals(asList(1, 3, 4, 5, 0), list);
    assertEquals(asList(0, 1, 3, 4, 5), list.sort());
}
Also used : GridLongList(org.apache.ignite.internal.util.GridLongList) Test(org.junit.Test)

Example 18 with GridLongList

use of org.apache.ignite.internal.util.GridLongList in project ignite by apache.

the class GridLongListSelfTest method testRemove.

/**
 */
@Test
public void testRemove() {
    GridLongList list = asList(1, 2, 3, 4, 5, 6);
    assertEquals(2, list.removeValue(0, 3));
    assertEquals(asList(1, 2, 4, 5, 6), list);
    assertEquals(-1, list.removeValue(1, 1));
    assertEquals(-1, list.removeValue(0, 3));
    assertEquals(4, list.removeValue(0, 6));
    assertEquals(asList(1, 2, 4, 5), list);
    assertEquals(2, list.removeIndex(1));
    assertEquals(asList(1, 4, 5), list);
    assertEquals(1, list.removeIndex(0));
    assertEquals(asList(4, 5), list);
}
Also used : GridLongList(org.apache.ignite.internal.util.GridLongList) Test(org.junit.Test)

Example 19 with GridLongList

use of org.apache.ignite.internal.util.GridLongList in project ignite by apache.

the class GridLongListSelfTest method testSerializationConstructorWithSize.

/**
 */
@Test
public void testSerializationConstructorWithSize() {
    MessageWriter writer = new DirectMessageWriter(GridIoManager.DIRECT_PROTO_VER);
    ByteBuffer buf = ByteBuffer.allocate(4096);
    GridLongList ll = new GridLongList(5);
    {
        Assert.assertTrue(ll.writeTo(buf, writer));
        Assert.assertEquals(HEADER_SIZE + 1 + /* array */
        1, /* index */
        buf.position());
    }
    {
        writer.reset();
        buf.clear();
        ll.add(2L);
        ll.add(4L);
        Assert.assertTrue(ll.writeTo(buf, writer));
        Assert.assertEquals(HEADER_SIZE + 17 + /* array */
        1, /* index */
        buf.position());
    }
    {
        writer.reset();
        buf.clear();
        ll.remove();
        Assert.assertTrue(ll.writeTo(buf, writer));
        Assert.assertEquals(HEADER_SIZE + 9 + /* array */
        1, /* index */
        buf.position());
    }
    {
        writer.reset();
        buf.clear();
        ll.remove();
        Assert.assertTrue(ll.writeTo(buf, writer));
        Assert.assertEquals(HEADER_SIZE + 1 + /* array */
        1, /* index */
        buf.position());
    }
    {
        writer.reset();
        buf.clear();
        for (int i = 0; i < 300; i++) ll.add(i);
        Assert.assertTrue(ll.writeTo(buf, writer));
        Assert.assertEquals(300, ll.size());
        Assert.assertEquals(HEADER_SIZE + 2402 + /* array */
        2, /* index */
        buf.position());
    }
    {
        writer.reset();
        buf.clear();
        ll.clear();
        Assert.assertTrue(ll.writeTo(buf, writer));
        Assert.assertEquals(HEADER_SIZE + 1 + /* array */
        1, /* index */
        buf.position());
    }
}
Also used : DirectMessageWriter(org.apache.ignite.internal.direct.DirectMessageWriter) GridLongList(org.apache.ignite.internal.util.GridLongList) DirectMessageWriter(org.apache.ignite.internal.direct.DirectMessageWriter) MessageWriter(org.apache.ignite.plugin.extensions.communication.MessageWriter) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 20 with GridLongList

use of org.apache.ignite.internal.util.GridLongList in project ignite by apache.

the class IgnitePdsPageReplacementDuringPartitionClearTest method testPageEvictionOnNodeStart.

/**
 * @throws Exception if failed.
 */
@Test
@WithSystemProperty(key = GridCacheDatabaseSharedManager.IGNITE_PDS_CHECKPOINT_TEST_SKIP_SYNC, value = "true")
public void testPageEvictionOnNodeStart() throws Exception {
    cleanPersistenceDir();
    startGrids(2);
    AtomicBoolean stop = new AtomicBoolean(false);
    try {
        Ignite ig = ignite(0);
        ig.cluster().active(true);
        ig.cluster().baselineAutoAdjustEnabled(false);
        int last = loadDataUntilPageReplacement(ignite(0), ignite(1));
        IgniteInternalFuture<?> fut = loadAsync(ig, stop, last);
        EvictionListener evictLsnr = new EvictionListener();
        ignite(0).events().localListen(evictLsnr, EVT_CACHE_REBALANCE_PART_UNLOADED);
        ignite(1).events().localListen(evictLsnr, EVT_CACHE_REBALANCE_PART_UNLOADED);
        IgniteEx igNew = startGrid(2);
        info(">>>>>>>>>>>");
        info(">>>>>>>>>>>");
        info(">>>>>>>>>>>");
        igNew.cluster().setBaselineTopology(3);
        awaitPartitionMapExchange();
        Map<ClusterNode, GridLongList> affinityAfter = allPartitions(igNew);
        evictLsnr.waitPartitionsEvicted(igNew.cluster().localNode(), affinityAfter);
        stop.set(true);
        fut.get();
    } finally {
        stop.set(true);
        stopAllGrids();
        cleanPersistenceDir();
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteEx(org.apache.ignite.internal.IgniteEx) GridLongList(org.apache.ignite.internal.util.GridLongList) Ignite(org.apache.ignite.Ignite) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty)

Aggregations

GridLongList (org.apache.ignite.internal.util.GridLongList)39 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)6 ByteBuffer (java.nio.ByteBuffer)5 DirectMessageWriter (org.apache.ignite.internal.direct.DirectMessageWriter)5 MessageWriter (org.apache.ignite.plugin.extensions.communication.MessageWriter)5 Map (java.util.Map)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 ClusterNode (org.apache.ignite.cluster.ClusterNode)4 IgniteException (org.apache.ignite.IgniteException)3 PagesListAddPageRecord (org.apache.ignite.internal.pagemem.wal.record.delta.PagesListAddPageRecord)3 PagesListInitNewPageRecord (org.apache.ignite.internal.pagemem.wal.record.delta.PagesListInitNewPageRecord)3 PagesListSetNextRecord (org.apache.ignite.internal.pagemem.wal.record.delta.PagesListSetNextRecord)3 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 TreeMap (java.util.TreeMap)2 UUID (java.util.UUID)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 PagesListMetaIO (org.apache.ignite.internal.processors.cache.persistence.freelist.io.PagesListMetaIO)2