ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [42/50] [abbrv] incubator-ignite git commit: # ignite-375 Add tests.
Date Thu, 19 Mar 2015 12:11:16 GMT
# ignite-375 Add tests.


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/2e6e93d3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/2e6e93d3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/2e6e93d3

Branch: refs/heads/ignite-437-sqltests
Commit: 2e6e93d33827348031bef3f061e387c172318140
Parents: 5c856ed
Author: anovikov <anovikov@gridgain.com>
Authored: Thu Mar 19 09:53:58 2015 +0700
Committer: anovikov <anovikov@gridgain.com>
Committed: Thu Mar 19 09:53:58 2015 +0700

----------------------------------------------------------------------
 .../store/jdbc/CacheAbstractJdbcStore.java      |  5 +-
 .../core/src/test/config/store/jdbc/Ignite.xml  | 28 +++++++
 .../store/jdbc/CacheJdbcPojoStoreTest.java      | 83 +++++++++++++++++++-
 3 files changed, 113 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2e6e93d3/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheAbstractJdbcStore.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheAbstractJdbcStore.java
b/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheAbstractJdbcStore.java
index 85c036f..6a43929 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheAbstractJdbcStore.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheAbstractJdbcStore.java
@@ -1197,12 +1197,13 @@ public abstract class CacheAbstractJdbcStore<K, V> implements
CacheStore<K, V>,
                 if (field.getJavaType() == UUID.class) {
                     switch (field.getDatabaseType()) {
                         case Types.BINARY:
-                            U.uuidToBytes((UUID)fieldVal);
-                            break;
+                            fieldVal = U.uuidToBytes((UUID)fieldVal);
 
+                            break;
                         case Types.CHAR:
                         case Types.VARCHAR:
                             fieldVal = fieldVal.toString();
+
                             break;
                     }
                 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2e6e93d3/modules/core/src/test/config/store/jdbc/Ignite.xml
----------------------------------------------------------------------
diff --git a/modules/core/src/test/config/store/jdbc/Ignite.xml b/modules/core/src/test/config/store/jdbc/Ignite.xml
index 3a64d60..91d77cd 100644
--- a/modules/core/src/test/config/store/jdbc/Ignite.xml
+++ b/modules/core/src/test/config/store/jdbc/Ignite.xml
@@ -237,4 +237,32 @@
             </list>
         </property>
     </bean>
+    <bean class="org.apache.ignite.cache.CacheTypeMetadata">
+        <property name="databaseSchema" value="PUBLIC"/>
+        <property name="databaseTable" value="TIMESTAMP_ENTRIES"/>
+        <property name="keyType" value="java.sql.Timestamp"/>
+        <property name="valueType" value="java.lang.Integer"/>
+        <property name="keyFields">
+            <list>
+                <bean class="org.apache.ignite.cache.CacheTypeFieldMetadata">
+                    <property name="databaseName" value="KEY"/>
+                    <property name="databaseType">
+                        <util:constant static-field="java.sql.Types.TIMESTAMP"/>
+                    </property>
+                    <property name="javaType" value="java.sql.Timestamp"/>
+                </bean>
+            </list>
+        </property>
+        <property name="valueFields">
+            <list>
+                <bean class="org.apache.ignite.cache.CacheTypeFieldMetadata">
+                    <property name="databaseName" value="VAL"/>
+                    <property name="databaseType">
+                        <util:constant static-field="java.sql.Types.INTEGER"/>
+                    </property>
+                    <property name="javaType" value="java.lang.Integer"/>
+                </bean>
+            </list>
+        </property>
+    </bean>
 </beans>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2e6e93d3/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStoreTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStoreTest.java
b/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStoreTest.java
index 76cc119..98308cb 100644
--- a/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStoreTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStoreTest.java
@@ -21,7 +21,7 @@ import org.apache.ignite.*;
 import org.apache.ignite.cache.*;
 import org.apache.ignite.cache.store.jdbc.dialect.*;
 import org.apache.ignite.cache.store.jdbc.model.*;
-import org.apache.ignite.internal.*;
+import org.apache.ignite.internal.processors.cache.*;
 import org.apache.ignite.internal.util.typedef.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
 import org.apache.ignite.lang.*;
@@ -33,6 +33,7 @@ import org.springframework.beans.factory.xml.*;
 import org.springframework.context.support.*;
 import org.springframework.core.io.*;
 
+import javax.cache.integration.*;
 import java.net.*;
 import java.sql.*;
 import java.util.*;
@@ -175,8 +176,16 @@ public class CacheJdbcPojoStoreTest extends GridAbstractCacheStoreSelfTest<Cache
             // No-op.
         }
 
+        try {
+            stmt.executeUpdate("delete from Timestamp_Entries");
+        }
+        catch (SQLException ignore) {
+            // No-op.
+        }
+
         stmt.executeUpdate("CREATE TABLE IF NOT EXISTS String_Entries (key varchar(100) not
null, val varchar(100), PRIMARY KEY(key))");
         stmt.executeUpdate("CREATE TABLE IF NOT EXISTS UUID_Entries (key binary(16) not null,
val binary(16), PRIMARY KEY(key))");
+        stmt.executeUpdate("CREATE TABLE IF NOT EXISTS Timestamp_Entries (key timestamp not
null, val integer, PRIMARY KEY(key))");
         stmt.executeUpdate("CREATE TABLE IF NOT EXISTS Organization (id integer not null,
name varchar(50), city varchar(50), PRIMARY KEY(id))");
         stmt.executeUpdate("CREATE TABLE IF NOT EXISTS Person (id integer not null, org_id
integer, name varchar(50), PRIMARY KEY(id))");
         stmt.executeUpdate("CREATE TABLE IF NOT EXISTS Person_Complex (id integer not null,
org_id integer not null, city_id integer not null, name varchar(50), PRIMARY KEY(id))");
@@ -307,4 +316,76 @@ public class CacheJdbcPojoStoreTest extends GridAbstractCacheStoreSelfTest<Cache
         assertTrue(prnKeys.isEmpty());
         assertTrue(prnComplexKeys.isEmpty());
     }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testWriteRetry() throws Exception {
+        // Special dialect that will skip updates, to test write retry.
+        BasicJdbcDialect dialect = new BasicJdbcDialect() {
+            /** {@inheritDoc} */
+            @Override public String updateQuery(String tblName, Collection<String>
keyCols, Iterable<String> valCols) {
+                return super.updateQuery(tblName, keyCols, valCols) + " AND 1 = 0";
+            }
+        };
+
+        store.setDialect(dialect);
+
+        Map<String, Map<Object, CacheAbstractJdbcStore.EntryMapping>> cacheMappings
=
+            GridTestUtils.getFieldValue(store, CacheAbstractJdbcStore.class, "cacheMappings");
+
+        CacheAbstractJdbcStore.EntryMapping em = cacheMappings.get(null).get(OrganizationKey.class);
+
+        CacheTypeMetadata typeMeta = GridTestUtils.getFieldValue(em, CacheAbstractJdbcStore.EntryMapping.class,
"typeMeta");
+
+        cacheMappings.get(null).put(OrganizationKey.class,
+            new CacheAbstractJdbcStore.EntryMapping(null, dialect, typeMeta));
+
+        Connection conn = store.openConnection(false);
+
+        PreparedStatement orgStmt = conn.prepareStatement("INSERT INTO Organization(id, name,
city) VALUES (?, ?, ?)");
+
+        orgStmt.setInt(1, 1);
+        orgStmt.setString(2, "name" + 1);
+        orgStmt.setString(3, "city" + 1);
+
+        orgStmt.executeUpdate();
+
+        U.closeQuiet(orgStmt);
+
+        conn.commit();
+
+        OrganizationKey k1 = new OrganizationKey(1);
+        Organization v1 = new Organization(1, "Name1", "City1");
+
+        ses.newSession(null);
+
+        try {
+            store.write(new CacheEntryImpl<>(k1, v1));
+        }
+        catch (CacheWriterException e) {
+            if (!e.getMessage().startsWith("Failed insert entry in database, violate a unique
index or primary key") ||
+                e.getSuppressed().length != 2)
+                throw e;
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testTimestamp() throws Exception {
+        Timestamp k = new Timestamp(System.currentTimeMillis());
+
+        ses.newSession(null);
+
+        Integer v = 5;
+
+        store.write(new CacheEntryImpl<>(k, v));
+
+        assertEquals(v, store.load(k));
+
+        store.delete(k);
+
+        assertNull(store.load(k));
+    }
 }


Mime
View raw message