Search in sources :

Example 1 with IgniteBinary

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

the class IgniteCacheBinaryEntryProcessorSelfTest method checkInvokeBinaryObject.

/**
     * @param cacheMode Cache mode to test.
     * @param atomicityMode Atomicity mode to test.
     * @throws Exception
     */
private void checkInvokeBinaryObject(CacheMode cacheMode, CacheAtomicityMode atomicityMode) throws Exception {
    Ignite client = ignite(SRV_CNT);
    IgniteCache<Integer, TestValue> clientCache = client.createCache(cacheConfiguration(cacheMode, atomicityMode));
    try {
        IgniteBinary binary = client.binary();
        for (int i = 0; i < 100; i++) {
            clientCache.put(i, new TestValue(i, "value-" + i));
            BinaryObjectBuilder bldr = binary.builder("NoClass");
            bldr.setField("val", i);
            bldr.setField("strVal", "value-" + i);
            clientCache.withKeepBinary().put(-(i + 1), bldr.build());
        }
        IgniteCache<Integer, BinaryObject> binaryClientCache = clientCache.withKeepBinary();
        for (int i = 0; i < 100; i++) {
            binaryClientCache.invoke(i, new TestEntryProcessor());
            binaryClientCache.invoke(-(i + 1), new TestEntryProcessor());
        }
        for (int g = 0; g < NODES; g++) {
            IgniteCache<Integer, TestValue> nodeCache = ignite(g).cache(DEFAULT_CACHE_NAME);
            IgniteCache<Integer, BinaryObject> nodeBinaryCache = nodeCache.withKeepBinary();
            for (int i = 0; i < 100; i++) {
                TestValue updated = nodeCache.get(i);
                assertEquals((Integer) (i + 1), updated.value());
                assertEquals("updated-" + i, updated.stringValue());
                BinaryObject updatedBinary = nodeBinaryCache.get(i);
                assertEquals(new Integer(i + 1), updatedBinary.field("val"));
                assertEquals("updated-" + i, updatedBinary.field("strVal"));
                updatedBinary = nodeBinaryCache.get(-(i + 1));
                assertEquals(new Integer(i + 1), updatedBinary.field("val"));
                assertEquals("updated-" + i, updatedBinary.field("strVal"));
            }
        }
    } finally {
        client.destroyCache(DEFAULT_CACHE_NAME);
    }
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) Ignite(org.apache.ignite.Ignite) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder) IgniteBinary(org.apache.ignite.IgniteBinary)

Example 2 with IgniteBinary

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

the class GridCacheClientNodeBinaryObjectMetadataMultinodeTest method testClientStartsFirst.

/**
     * @throws Exception If failed.
     */
public void testClientStartsFirst() throws Exception {
    client = true;
    final Ignite ignite0 = startGrid(0);
    assertTrue(ignite0.configuration().isClientMode());
    client = false;
    Ignite ignite1 = startGrid(1);
    assertFalse(ignite1.configuration().isClientMode());
    IgniteBinary binaries = ignite(1).binary();
    IgniteCache<Object, Object> cache = ignite(1).cache(DEFAULT_CACHE_NAME).withKeepBinary();
    for (int i = 0; i < 100; i++) {
        BinaryObjectBuilder builder = binaries.builder("type-" + i);
        builder.setField("f0", i);
        cache.put(i, builder.build());
    }
    GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            return ignite0.binary().types().size() == 100;
        }
    }, 5000);
    assertEquals(100, ignite(0).binary().types().size());
}
Also used : GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) Ignite(org.apache.ignite.Ignite) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder) IgniteBinary(org.apache.ignite.IgniteBinary)

Example 3 with IgniteBinary

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

the class GridCacheClientNodeBinaryObjectMetadataMultinodeTest method testClientMetadataInitialization.

/**
     * @throws Exception If failed.
     */
public void testClientMetadataInitialization() throws Exception {
    startGrids(2);
    final AtomicBoolean stop = new AtomicBoolean();
    final ConcurrentHashSet<String> allTypes = new ConcurrentHashSet<>();
    IgniteInternalFuture<?> fut;
    try {
        // Update binary metadata concurrently with client nodes start.
        fut = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                IgniteBinary binaries = ignite(0).binary();
                IgniteCache<Object, Object> cache = ignite(0).cache(DEFAULT_CACHE_NAME).withKeepBinary();
                ThreadLocalRandom rnd = ThreadLocalRandom.current();
                for (int i = 0; i < 1000; i++) {
                    log.info("Iteration: " + i);
                    String type = "binary-type-" + i;
                    allTypes.add(type);
                    for (int f = 0; f < 10; f++) {
                        BinaryObjectBuilder builder = binaries.builder(type);
                        String fieldName = "f" + f;
                        builder.setField(fieldName, i);
                        cache.put(rnd.nextInt(0, 100_000), builder.build());
                        if (f % 100 == 0)
                            log.info("Put iteration: " + f);
                    }
                    if (stop.get())
                        break;
                }
                return null;
            }
        }, 5, "update-thread");
    } finally {
        stop.set(true);
    }
    client = true;
    startGridsMultiThreaded(2, 5);
    fut.get();
    assertFalse(allTypes.isEmpty());
    log.info("Expected binary types: " + allTypes.size());
    assertEquals(7, ignite(0).cluster().nodes().size());
    for (int i = 0; i < 7; i++) {
        log.info("Check metadata on node: " + i);
        boolean client = i > 1;
        assertEquals((Object) client, ignite(i).configuration().isClientMode());
        IgniteBinary binaries = ignite(i).binary();
        Collection<BinaryType> metaCol = binaries.types();
        assertEquals(allTypes.size(), metaCol.size());
        Set<String> names = new HashSet<>();
        for (BinaryType meta : metaCol) {
            info("Binary type: " + meta);
            assertTrue(names.add(meta.typeName()));
            assertNull(meta.affinityKeyFieldName());
            assertEquals(10, meta.fieldNames().size());
        }
        assertEquals(allTypes.size(), names.size());
    }
}
Also used : BinaryType(org.apache.ignite.binary.BinaryType) Callable(java.util.concurrent.Callable) IgniteBinary(org.apache.ignite.IgniteBinary) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ConcurrentHashSet(org.eclipse.jetty.util.ConcurrentHashSet) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder) ConcurrentHashSet(org.eclipse.jetty.util.ConcurrentHashSet) HashSet(java.util.HashSet)

Example 4 with IgniteBinary

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

the class JdbcResultSetSelfTest method testObject.

/**
     * @throws Exception If failed.
     */
public void testObject() throws Exception {
    final Ignite ignite = ignite(0);
    final boolean binaryMarshaller = ignite.configuration().getMarshaller() instanceof BinaryMarshaller;
    final IgniteBinary binary = binaryMarshaller ? ignite.binary() : null;
    ResultSet rs = stmt.executeQuery(SQL);
    TestObjectField f1 = new TestObjectField(100, "AAAA");
    TestObjectField f2 = new TestObjectField(500, "BBBB");
    TestObject o = createObjectWithData(1);
    assertTrue(rs.next());
    assertEqualsToStringRepresentation(f1, binary, rs.getObject("f1"));
    assertEqualsToStringRepresentation(f1, binary, rs.getObject(16));
    assertEqualsToStringRepresentation(f2, binary, rs.getObject("f2"));
    assertEqualsToStringRepresentation(f2, binary, rs.getObject(17));
    assertNull(rs.getObject("f3"));
    assertTrue(rs.wasNull());
    assertNull(rs.getObject(18));
    assertTrue(rs.wasNull());
    assertEqualsToStringRepresentation(o, binary, rs.getObject("_val"));
    assertEqualsToStringRepresentation(o, binary, rs.getObject(19));
    assertFalse(rs.next());
}
Also used : BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) ResultSet(java.sql.ResultSet) Ignite(org.apache.ignite.Ignite) IgniteBinary(org.apache.ignite.IgniteBinary)

Example 5 with IgniteBinary

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

the class JdbcResultSetSelfTest method testObject.

/**
     * @throws Exception If failed.
     */
public void testObject() throws Exception {
    final Ignite ignite = ignite(0);
    final boolean binaryMarshaller = ignite.configuration().getMarshaller() instanceof BinaryMarshaller;
    final IgniteBinary binary = binaryMarshaller ? ignite.binary() : null;
    ResultSet rs = stmt.executeQuery(SQL);
    TestObjectField f1 = new TestObjectField(100, "AAAA");
    TestObjectField f2 = new TestObjectField(500, "BBBB");
    TestObject o = createObjectWithData(1);
    assertTrue(rs.next());
    assertEqualsToStringRepresentation(f1, binary, rs.getObject("f1"));
    assertEqualsToStringRepresentation(f1, binary, rs.getObject(16));
    assertEqualsToStringRepresentation(f2, binary, rs.getObject("f2"));
    assertEqualsToStringRepresentation(f2, binary, rs.getObject(17));
    assertNull(rs.getObject("f3"));
    assertTrue(rs.wasNull());
    assertNull(rs.getObject(18));
    assertTrue(rs.wasNull());
    assertEqualsToStringRepresentation(o, binary, rs.getObject("_val"));
    assertEqualsToStringRepresentation(o, binary, rs.getObject(19));
    assertFalse(rs.next());
}
Also used : BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) Ignite(org.apache.ignite.Ignite) IgniteBinary(org.apache.ignite.IgniteBinary)

Aggregations

IgniteBinary (org.apache.ignite.IgniteBinary)11 Ignite (org.apache.ignite.Ignite)7 BinaryObjectBuilder (org.apache.ignite.binary.BinaryObjectBuilder)7 BinaryObject (org.apache.ignite.binary.BinaryObject)4 HashSet (java.util.HashSet)2 BinaryType (org.apache.ignite.binary.BinaryType)2 BinaryMarshaller (org.apache.ignite.internal.binary.BinaryMarshaller)2 GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)2 ConcurrentHashSet (org.eclipse.jetty.util.ConcurrentHashSet)2 ResultSet (java.sql.ResultSet)1 Collection (java.util.Collection)1 Callable (java.util.concurrent.Callable)1 CyclicBarrier (java.util.concurrent.CyclicBarrier)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 SqlQuery (org.apache.ignite.cache.query.SqlQuery)1 IgniteEx (org.apache.ignite.internal.IgniteEx)1 Transaction (org.apache.ignite.transactions.Transaction)1