ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [1/2] incubator-ignite git commit: # IGNITE-32 WIP: Multi threading.
Date Tue, 20 Jan 2015 06:16:30 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-32 9c6f98641 -> 6a8a5aa88


# IGNITE-32 WIP: Multi threading.


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

Branch: refs/heads/ignite-32
Commit: 8241ac17d2ffa003ae0b894429daa962d98b3529
Parents: 9c6f986
Author: AKuznetsov <akuznetsov@gridgain.com>
Authored: Tue Jan 20 13:16:24 2015 +0700
Committer: AKuznetsov <akuznetsov@gridgain.com>
Committed: Tue Jan 20 13:16:24 2015 +0700

----------------------------------------------------------------------
 .../grid/cache/store/auto/PojoCacheStore.java   |   4 +-
 .../PojoCacheStoreMultithreadedSelfTest.java    | 210 +++++++++++++++++++
 .../store/auto/PojoCacheStoreSelfTest.java      |   2 +-
 3 files changed, 213 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8241ac17/modules/core/src/main/java/org/gridgain/grid/cache/store/auto/PojoCacheStore.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/gridgain/grid/cache/store/auto/PojoCacheStore.java
b/modules/core/src/main/java/org/gridgain/grid/cache/store/auto/PojoCacheStore.java
index a504238..8c9cbbb 100644
--- a/modules/core/src/main/java/org/gridgain/grid/cache/store/auto/PojoCacheStore.java
+++ b/modules/core/src/main/java/org/gridgain/grid/cache/store/auto/PojoCacheStore.java
@@ -171,9 +171,9 @@ public class PojoCacheStore extends AutoCacheStore<Object, Object>
{
     @Nullable @Override protected Object extractField(String typeName, String fieldName,
Object obj)
         throws IgniteCheckedException {
         try {
-            PojoMethodsCache t = mtdsCache.get(typeName);
+            PojoMethodsCache mc = mtdsCache.get(typeName);
 
-            return t.getters.get(fieldName).invoke(obj);
+            return mc.getters.get(fieldName).invoke(obj);
         }
         catch (Exception e) {
             throw new IgniteCheckedException("Failed to read object of class: " + typeName,
e);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8241ac17/modules/core/src/test/java/org/apache/ignite/cache/store/auto/PojoCacheStoreMultithreadedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/cache/store/auto/PojoCacheStoreMultithreadedSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/cache/store/auto/PojoCacheStoreMultithreadedSelfTest.java
new file mode 100644
index 0000000..55a42aa
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/cache/store/auto/PojoCacheStoreMultithreadedSelfTest.java
@@ -0,0 +1,210 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* @java.file.header */
+
+/*  _________        _____ __________________        _____
+ *  __  ____/___________(_)______  /__  ____/______ ____(_)_______
+ *  _  / __  __  ___/__  / _  __  / _  / __  _  __ `/__  / __  __ \
+ *  / /_/ /  _  /    _  /  / /_/ /  / /_/ /  / /_/ / _  /  _  / / /
+ *  \____/   /_/     /_/   \_,__/   \____/   \__,_/  /_/   /_/ /_/
+ */
+
+package org.apache.ignite.cache.store.auto;
+
+import org.apache.ignite.*;
+import org.apache.ignite.cache.store.auto.model.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.spi.discovery.tcp.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*;
+import org.gridgain.grid.cache.*;
+import org.gridgain.grid.cache.query.*;
+import org.gridgain.grid.cache.store.auto.*;
+import org.gridgain.grid.util.typedef.*;
+import org.gridgain.grid.util.typedef.internal.*;
+import org.gridgain.testframework.junits.common.*;
+import org.jetbrains.annotations.*;
+import org.springframework.beans.*;
+import org.springframework.beans.factory.xml.*;
+import org.springframework.context.support.*;
+import org.springframework.core.io.*;
+
+import java.io.*;
+import java.net.*;
+import java.sql.*;
+import java.util.*;
+import java.util.concurrent.*;
+
+import static org.gridgain.grid.cache.GridCacheAtomicityMode.*;
+import static org.gridgain.grid.cache.GridCacheMode.*;
+import static org.gridgain.testframework.GridTestUtils.*;
+
+/**
+ *
+ */
+public class PojoCacheStoreMultithreadedSelfTest extends GridCommonAbstractTest {
+    /** Default connection URL (value is <tt>jdbc:h2:mem:jdbcCacheStore;DB_CLOSE_DELAY=-1</tt>).
*/
+    protected static final String DFLT_CONN_URL = "jdbc:h2:mem:autoCacheStore;DB_CLOSE_DELAY=-1";
+
+    /** IP finder. */
+    private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
+
+    /** Number of transactions. */
+    private static final int TX_CNT = 1000;
+
+    /** Number of transactions. */
+    private static final int BATCH_CNT = 2000;
+
+    /** Cache store. */
+    private static PojoCacheStore store;
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        Class.forName("org.h2.Driver");
+        Connection conn = DriverManager.getConnection(DFLT_CONN_URL, "sa", "");
+
+        Statement stmt = conn.createStatement();
+
+        stmt.executeUpdate("DROP TABLE IF EXISTS Organization");
+        stmt.executeUpdate("DROP TABLE IF EXISTS Person");
+
+        stmt.executeUpdate("CREATE TABLE Organization (id integer PRIMARY KEY, name varchar(50),
city varchar(50))");
+        stmt.executeUpdate("CREATE TABLE Person (id integer PRIMARY KEY, org_id integer,
name varchar(50))");
+
+        stmt.executeUpdate("CREATE INDEX Org_Name_IDX On Organization (name)");
+        stmt.executeUpdate("CREATE INDEX Org_Name_City_IDX On Organization (name, city)");
+        stmt.executeUpdate("CREATE INDEX Person_Name_IDX1 On Person (name)");
+        stmt.executeUpdate("CREATE INDEX Person_Name_IDX2 On Person (name desc)");
+
+        conn.commit();
+
+        U.closeQuiet(stmt);
+
+        U.closeQuiet(conn);
+
+        store = store();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+    }
+
+    /**
+     * @return New store.
+     * @throws Exception In case of error.
+     */
+    private PojoCacheStore store() throws Exception {
+        PojoCacheStore store = new PojoCacheStore();
+
+        store.setConnUrl(DFLT_CONN_URL);
+        store.setUser("sa");
+        store.setPassword("");
+
+        UrlResource metaUrl;
+
+        try {
+            metaUrl = new UrlResource(new File("modules/core/src/test/config/store/auto/all.xml").toURI().toURL());
+        }
+        catch (MalformedURLException e) {
+            throw new IgniteCheckedException("Failed to resolve metadata path [err=" + e.getMessage()
+ ']', e);
+        }
+
+        try {
+            GenericApplicationContext springCtx = new GenericApplicationContext();
+
+            new XmlBeanDefinitionReader(springCtx).loadBeanDefinitions(metaUrl);
+
+            springCtx.refresh();
+
+            Collection<GridCacheQueryTypeMetadata> typeMetadata =
+                springCtx.getBeansOfType(GridCacheQueryTypeMetadata.class).values();
+
+            store.setTypeMetadata(typeMetadata);
+        }
+        catch (BeansException e) {
+            if (X.hasCause(e, ClassNotFoundException.class))
+                throw new IgniteCheckedException("Failed to instantiate Spring XML application
context " +
+                    "(make sure all classes used in Spring configuration are present at CLASSPATH)
" +
+                    "[springUrl=" + metaUrl + ']', e);
+            else
+                throw new IgniteCheckedException("Failed to instantiate Spring XML application
context [springUrl=" +
+                    metaUrl + ", err=" + e.getMessage() + ']', e);
+        }
+
+        return store;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected final IgniteConfiguration getConfiguration(String gridName) throws
Exception {
+        IgniteConfiguration c = super.getConfiguration(gridName);
+
+        TcpDiscoverySpi disco = new TcpDiscoverySpi();
+
+        disco.setIpFinder(IP_FINDER);
+
+        c.setDiscoverySpi(disco);
+
+        GridCacheConfiguration cc = defaultCacheConfiguration();
+
+        cc.setCacheMode(PARTITIONED);
+        cc.setAtomicityMode(ATOMIC);
+        cc.setSwapEnabled(false);
+        cc.setWriteBehindEnabled(false);
+
+        cc.setStore(store);
+
+        c.setCacheConfiguration(cc);
+
+        return c;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testMultithreadedPutAll() throws Exception {
+        startGrid();
+
+        runMultiThreaded(new Callable<Object>() {
+            private final Random rnd = new Random();
+
+            @Nullable @Override public Object call() throws Exception {
+                for (int i = 0; i < TX_CNT; i++) {
+                    int cnt = rnd.nextInt(BATCH_CNT);
+
+                    Map<Object, Object> map = U.newHashMap(cnt);
+
+                    for (int j = 0; j < cnt; j++) {
+                        int id = rnd.nextInt();
+
+                        if (rnd.nextBoolean())
+                            map.put(new OrganizationKey(id), new Organization(id, "Name"
+ id, "City" + id));
+                        else
+                            map.put(new PersonKey(id), new Person(id, rnd.nextInt(), "Name"
+ id));
+                    }
+
+                    GridCache<Object, Object> cache = cache();
+
+                    cache.putAll(map);
+                }
+
+                return null;
+            }
+        }, 8, "putAll");
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8241ac17/modules/core/src/test/java/org/apache/ignite/cache/store/auto/PojoCacheStoreSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/cache/store/auto/PojoCacheStoreSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/cache/store/auto/PojoCacheStoreSelfTest.java
index 22e18c0..83d3e7c 100644
--- a/modules/core/src/test/java/org/apache/ignite/cache/store/auto/PojoCacheStoreSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/cache/store/auto/PojoCacheStoreSelfTest.java
@@ -41,7 +41,7 @@ import java.util.concurrent.*;
 import java.util.concurrent.atomic.*;
 
 /**
- * class for {@code PojoCacheStore} tests.
+ * Class for {@code PojoCacheStore} tests.
  */
 public class PojoCacheStoreSelfTest extends GridCommonAbstractTest {
     /** Default connection URL (value is <tt>jdbc:h2:mem:jdbcCacheStore;DB_CLOSE_DELAY=-1</tt>).
*/


Mime
View raw message