Search in sources :

Example 1 with GridByteArrayInputStream

use of org.apache.ignite.internal.util.io.GridByteArrayInputStream in project ignite by apache.

the class GridCacheReplicatedQueueRemoveSelfTest method testQueueRemovalProcessor.

/**
 * This a unit test of Ignite queue's RemoveProcessor process() method.
 *
 * @throws Exception If failed.
 */
@Test
@SuppressWarnings("unchecked")
public void testQueueRemovalProcessor() throws Exception {
    GridCacheContext cctx = grid(0).context().cache().cache("ignite-sys-cache").context();
    IgniteUuid id = IgniteUuid.randomUuid();
    CacheInvokeEntry entry = new CacheInvokeEntry<>(null, null, null, false, new GridDhtCacheEntry(cctx, null, new KeyCacheObjectImpl(1, BigInteger.valueOf(1).toByteArray(), 1)));
    entry.setValue(new GridCacheQueueHeader(id, 2147483647, false, 0L, 10000L, Collections.singleton(1L)));
    GridCacheQueueAdapter.RemoveProcessor rp = new GridCacheQueueAdapter.RemoveProcessor(id, 1L);
    rp.process(entry);
    GridCacheQueueAdapter.RemoveProcessor externalRP = new GridCacheQueueAdapter.RemoveProcessor();
    GridByteArrayOutputStream output = new GridByteArrayOutputStream();
    rp.writeExternal(new ObjectOutputStream(output));
    externalRP.readExternal(new ObjectInputStream(new GridByteArrayInputStream(output.toByteArray())));
    assertEquals(id, GridTestUtils.getFieldValue(externalRP, "id"));
    // idx should be null, cause entry was already removed, see GridCacheQueueAdapter.RemoveProcessor.code
    // for more details.
    assertNull(GridTestUtils.getFieldValue(externalRP, "idx"));
}
Also used : GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) GridByteArrayOutputStream(org.apache.ignite.internal.util.io.GridByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) GridDhtCacheEntry(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry) CacheInvokeEntry(org.apache.ignite.internal.processors.cache.CacheInvokeEntry) GridByteArrayInputStream(org.apache.ignite.internal.util.io.GridByteArrayInputStream) IgniteUuid(org.apache.ignite.lang.IgniteUuid) KeyCacheObjectImpl(org.apache.ignite.internal.processors.cache.KeyCacheObjectImpl) ObjectInputStream(java.io.ObjectInputStream) IgniteCollectionAbstractTest(org.apache.ignite.internal.processors.cache.datastructures.IgniteCollectionAbstractTest) Test(org.junit.Test)

Aggregations

ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 CacheInvokeEntry (org.apache.ignite.internal.processors.cache.CacheInvokeEntry)1 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)1 KeyCacheObjectImpl (org.apache.ignite.internal.processors.cache.KeyCacheObjectImpl)1 IgniteCollectionAbstractTest (org.apache.ignite.internal.processors.cache.datastructures.IgniteCollectionAbstractTest)1 GridDhtCacheEntry (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry)1 GridByteArrayInputStream (org.apache.ignite.internal.util.io.GridByteArrayInputStream)1 GridByteArrayOutputStream (org.apache.ignite.internal.util.io.GridByteArrayOutputStream)1 IgniteUuid (org.apache.ignite.lang.IgniteUuid)1 Test (org.junit.Test)1