Search in sources :

Example 6 with IgniteBinary

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

the class CacheQueryBuildValueTest method testBuilderAndQuery.

/**
     * @throws Exception If failed.
     */
public void testBuilderAndQuery() throws Exception {
    Ignite node = ignite(0);
    final IgniteCache<Object, Object> cache = node.cache(DEFAULT_CACHE_NAME);
    IgniteBinary binary = node.binary();
    BinaryObjectBuilder builder = binary.builder(TestBuilderValue.class.getName());
    cache.put(0, builder.build());
    builder.setField("iVal", 1);
    cache.put(1, builder.build());
    List<Cache.Entry<Object, Object>> entries = cache.query(new SqlQuery<>(TestBuilderValue.class, "true")).getAll();
    assertEquals(2, entries.size());
}
Also used : SqlQuery(org.apache.ignite.cache.query.SqlQuery) Ignite(org.apache.ignite.Ignite) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder) IgniteBinary(org.apache.ignite.IgniteBinary)

Example 7 with IgniteBinary

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

the class IgniteCacheAbstractQuerySelfTest method testEnumObjectQuery.

/**
     * JUnit.
     *
     * @throws Exception In case of error.
     */
public void testEnumObjectQuery() throws Exception {
    final IgniteCache<Long, EnumObject> cache = jcache(Long.class, EnumObject.class);
    for (long i = 0; i < 50; i++) cache.put(i, new EnumObject(i, i % 2 == 0 ? EnumType.TYPE_A : EnumType.TYPE_B));
    assertEnumQry("type = ?", EnumType.TYPE_A, EnumType.TYPE_A, cache, 25);
    assertEnumQry("type > ?", EnumType.TYPE_A, EnumType.TYPE_B, cache, 25);
    assertEnumQry("type < ?", EnumType.TYPE_B, EnumType.TYPE_A, cache, 25);
    assertEnumQry("type != ?", EnumType.TYPE_B, EnumType.TYPE_A, cache, 25);
    assertEmptyEnumQry("type = ?", null, cache);
    assertEmptyEnumQry("type > ?", EnumType.TYPE_B, cache);
    assertEmptyEnumQry("type < ?", EnumType.TYPE_A, cache);
    cache.put(50L, new EnumObject(50, null));
    assertNoArgEnumQry("type is null", null, cache, 1);
    assertAnyResTypeEnumQry("type is not null", cache, 50);
    // Additional tests for binary enums.
    IgniteBinary binary = ignite().binary();
    if (binary != null) {
        assertEnumQry("type = ?", binaryEnum(binary, EnumType.TYPE_A), EnumType.TYPE_A, cache, 25);
        assertEnumQry("type > ?", binaryEnum(binary, EnumType.TYPE_A), EnumType.TYPE_B, cache, 25);
        assertEnumQry("type < ?", binaryEnum(binary, EnumType.TYPE_B), EnumType.TYPE_A, cache, 25);
        assertEnumQry("type != ?", binaryEnum(binary, EnumType.TYPE_B), EnumType.TYPE_A, cache, 25);
        assertEmptyEnumQry("type > ?", binaryEnum(binary, EnumType.TYPE_B), cache);
        assertEmptyEnumQry("type < ?", binaryEnum(binary, EnumType.TYPE_A), cache);
    }
}
Also used : IgniteBinary(org.apache.ignite.IgniteBinary)

Example 8 with IgniteBinary

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

the class BinarySimpleNameTestPropertySelfTest method checkProperty.

/**
     * @param expTypeName Type name.
     * @throws Exception If failed.
     */
private void checkProperty(String expTypeName) throws Exception {
    String marshBackup = GridTestProperties.getProperty(MARSH_CLASS_NAME);
    try {
        GridTestProperties.setProperty(MARSH_CLASS_NAME, BinaryMarshaller.class.getName());
        IgniteBinary binary = startGrid().binary();
        BinaryObjectBuilder builder = binary.builder("org.ignite.test.TestClass");
        BinaryObject bObj = builder.build();
        assertEquals(expTypeName, bObj.type().typeName());
    } finally {
        if (marshBackup != null)
            GridTestProperties.setProperty(MARSH_CLASS_NAME, marshBackup);
    }
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder) IgniteBinary(org.apache.ignite.IgniteBinary)

Example 9 with IgniteBinary

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

the class CacheKeepBinaryTransactionTest method testBinaryPutGetContains.

/**
     * @throws Exception If failed.
     */
public void testBinaryPutGetContains() throws Exception {
    IgniteEx ignite = grid(0);
    IgniteCache<Object, Object> cache = ignite.cache("tx-cache").withKeepBinary();
    try (Transaction tx = ignite.transactions().txStart()) {
        IgniteBinary binary = ignite.binary();
        BinaryObject key = binary.builder("test-key").setField("id", 1).build();
        BinaryObject val = binary.builder("test-val").setField("id", 22).build();
        cache.put(key, val);
        assertTrue(cache.containsKey(key));
        assertEquals(val, cache.get(key));
    }
}
Also used : Transaction(org.apache.ignite.transactions.Transaction) BinaryObject(org.apache.ignite.binary.BinaryObject) IgniteEx(org.apache.ignite.internal.IgniteEx) BinaryObject(org.apache.ignite.binary.BinaryObject) IgniteBinary(org.apache.ignite.IgniteBinary)

Example 10 with IgniteBinary

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

the class GridCacheClientNodeBinaryObjectMetadataMultinodeTest method testFailoverOnStart.

/**
     * @throws Exception If failed.
     */
public void testFailoverOnStart() throws Exception {
    startGrids(4);
    IgniteBinary binaries = ignite(0).binary();
    IgniteCache<Object, Object> cache = ignite(0).cache(DEFAULT_CACHE_NAME).withKeepBinary();
    for (int i = 0; i < 1000; i++) {
        BinaryObjectBuilder builder = binaries.builder("type-" + i);
        builder.setField("f0", i);
        cache.put(i, builder.build());
    }
    client = true;
    final CyclicBarrier barrier = new CyclicBarrier(6);
    final AtomicInteger startIdx = new AtomicInteger(4);
    IgniteInternalFuture<?> fut = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            barrier.await();
            Ignite ignite = startGrid(startIdx.getAndIncrement());
            assertTrue(ignite.configuration().isClientMode());
            log.info("Started node: " + ignite.name());
            return null;
        }
    }, 5, "start-thread");
    barrier.await();
    U.sleep(ThreadLocalRandom.current().nextInt(10, 100));
    for (int i = 0; i < 3; i++) stopGrid(i);
    fut.get();
    assertEquals(6, ignite(3).cluster().nodes().size());
    for (int i = 3; i < 7; i++) {
        log.info("Check metadata on node: " + i);
        boolean client = i > 3;
        assertEquals((Object) client, ignite(i).configuration().isClientMode());
        binaries = ignite(i).binary();
        final IgniteBinary p0 = binaries;
        GridTestUtils.waitForCondition(new GridAbsPredicate() {

            @Override
            public boolean apply() {
                Collection<BinaryType> metaCol = p0.types();
                return metaCol.size() == 1000;
            }
        }, getTestTimeout());
        Collection<BinaryType> metaCol = binaries.types();
        assertEquals(1000, metaCol.size());
        Set<String> names = new HashSet<>();
        for (BinaryType meta : metaCol) {
            assertTrue(names.add(meta.typeName()));
            assertNull(meta.affinityKeyFieldName());
            assertEquals(1, meta.fieldNames().size());
        }
        assertEquals(1000, names.size());
    }
}
Also used : BinaryType(org.apache.ignite.binary.BinaryType) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) IgniteBinary(org.apache.ignite.IgniteBinary) CyclicBarrier(java.util.concurrent.CyclicBarrier) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Collection(java.util.Collection) Ignite(org.apache.ignite.Ignite) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder) ConcurrentHashSet(org.eclipse.jetty.util.ConcurrentHashSet) HashSet(java.util.HashSet)

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