ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [25/70] [abbrv] ignite git commit: ignite-4982 Fixed GridIntList.
Date Thu, 20 Apr 2017 07:48:58 GMT
ignite-4982 Fixed GridIntList.


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

Branch: refs/heads/ignite-2893
Commit: d60cf53bbfae162ac96ec1525bcd1772b8249a79
Parents: 58a8cb2
Author: Konstantin Dudkov <kdudkov@ya.ru>
Authored: Tue Apr 18 16:50:16 2017 +0300
Committer: sboikov <sboikov@gridgain.com>
Committed: Tue Apr 18 16:50:16 2017 +0300

----------------------------------------------------------------------
 .../communication/GridIoMessageFactory.java     |   8 +-
 .../ignite/internal/util/GridIntList.java       |   5 +-
 ...ClientWriteBehindStoreNonCoalescingTest.java |  13 +-
 .../testsuites/IgniteUtilSelfTestSuite.java     |   2 +
 .../apache/ignite/util/GridIntListSelfTest.java | 153 +++++++++++++++++++
 5 files changed, 167 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/d60cf53b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java
b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java
index e1c9511..b972a31 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java
@@ -36,7 +36,6 @@ import org.apache.ignite.internal.managers.eventstorage.GridEventStorageMessage;
 import org.apache.ignite.internal.pagemem.snapshot.SnapshotFinishedMessage;
 import org.apache.ignite.internal.pagemem.snapshot.SnapshotProgressMessage;
 import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
-import org.apache.ignite.internal.processors.cache.GridChangeGlobalStateMessageResponse;
 import org.apache.ignite.internal.processors.cache.CacheEntryInfoCollection;
 import org.apache.ignite.internal.processors.cache.CacheEntryPredicateContainsValue;
 import org.apache.ignite.internal.processors.cache.CacheEntrySerializablePredicate;
@@ -46,6 +45,7 @@ import org.apache.ignite.internal.processors.cache.CacheObjectByteArrayImpl;
 import org.apache.ignite.internal.processors.cache.CacheObjectImpl;
 import org.apache.ignite.internal.processors.cache.GridCacheEntryInfo;
 import org.apache.ignite.internal.processors.cache.GridCacheReturn;
+import org.apache.ignite.internal.processors.cache.GridChangeGlobalStateMessageResponse;
 import org.apache.ignite.internal.processors.cache.KeyCacheObjectImpl;
 import org.apache.ignite.internal.processors.cache.binary.MetadataRequestMessage;
 import org.apache.ignite.internal.processors.cache.binary.MetadataResponseMessage;
@@ -144,6 +144,7 @@ import org.apache.ignite.internal.processors.query.h2.twostep.messages.GridQuery
 import org.apache.ignite.internal.processors.rest.handlers.task.GridTaskResultRequest;
 import org.apache.ignite.internal.processors.rest.handlers.task.GridTaskResultResponse;
 import org.apache.ignite.internal.util.GridByteArrayList;
+import org.apache.ignite.internal.util.GridIntList;
 import org.apache.ignite.internal.util.GridLongList;
 import org.apache.ignite.internal.util.GridMessageCollection;
 import org.apache.ignite.internal.util.UUIDCollectionMessage;
@@ -176,6 +177,11 @@ public class GridIoMessageFactory implements MessageFactory {
         Message msg = null;
 
         switch (type) {
+            case -52:
+                msg = new GridIntList();
+
+                break;
+
             case -51:
                 msg = new NearCacheUpdates();
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/d60cf53b/modules/core/src/main/java/org/apache/ignite/internal/util/GridIntList.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/GridIntList.java b/modules/core/src/main/java/org/apache/ignite/internal/util/GridIntList.java
index 1de8106..968b88e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/GridIntList.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/GridIntList.java
@@ -132,8 +132,7 @@ public class GridIntList implements Message, Externalizable {
 
         for (int i = 0; i < idx; i++) {
             int element  = arr[i];
-            int elementHash = (int)(element ^ (element >>> 32));
-            res = 31 * res + elementHash;
+            res = 31 * res + element;
         }
 
         return res;
@@ -577,7 +576,7 @@ public class GridIntList implements Message, Externalizable {
 
     /** {@inheritDoc} */
     @Override public short directType() {
-        return 85;
+        return -52;
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/d60cf53b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/store/IgnteCacheClientWriteBehindStoreNonCoalescingTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/store/IgnteCacheClientWriteBehindStoreNonCoalescingTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/store/IgnteCacheClientWriteBehindStoreNonCoalescingTest.java
index 8ea109d..1d44a98 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/store/IgnteCacheClientWriteBehindStoreNonCoalescingTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/store/IgnteCacheClientWriteBehindStoreNonCoalescingTest.java
@@ -29,7 +29,6 @@ import javax.cache.processor.EntryProcessorException;
 import javax.cache.processor.MutableEntry;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCache;
-import org.apache.ignite.cache.CacheAtomicWriteOrderMode;
 import org.apache.ignite.cache.CacheAtomicityMode;
 import org.apache.ignite.cache.CacheMode;
 import org.apache.ignite.cache.store.CacheStore;
@@ -40,7 +39,6 @@ import org.apache.ignite.internal.processors.cache.IgniteCacheAbstractTest;
 import org.apache.ignite.lang.IgniteBiInClosure;
 import org.apache.ignite.lang.IgniteFuture;
 
-import static org.apache.ignite.cache.CacheAtomicWriteOrderMode.CLOCK;
 import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
 
 /**
@@ -63,11 +61,6 @@ public class IgnteCacheClientWriteBehindStoreNonCoalescingTest extends
IgniteCac
     }
 
     /** {@inheritDoc} */
-    @Override protected CacheAtomicWriteOrderMode atomicWriteOrderMode() {
-        return CLOCK;
-    }
-
-    /** {@inheritDoc} */
     @Override protected NearCacheConfiguration nearConfiguration() {
         return null;
     }
@@ -155,10 +148,10 @@ public class IgnteCacheClientWriteBehindStoreNonCoalescingTest extends
IgniteCac
 
         /** {@inheritDoc} */
         @Override public void write(Cache.Entry<? extends Object, ? extends Object>
entry) {
-            Object oldValue = storeMap.put(entry.getKey(), entry.getValue());
+            Object oldVal = storeMap.put(entry.getKey(), entry.getValue());
 
-            if (oldValue instanceof Integer && entry.getValue() instanceof Integer)
{
-                Integer oldInt = (Integer)oldValue;
+            if (oldVal instanceof Integer && entry.getValue() instanceof Integer)
{
+                Integer oldInt = (Integer) oldVal;
                 Integer newInt = (Integer)entry.getValue();
 
                 assertTrue(

http://git-wip-us.apache.org/repos/asf/ignite/blob/d60cf53b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteUtilSelfTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteUtilSelfTestSuite.java
b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteUtilSelfTestSuite.java
index 066f8ea..64a94fd 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteUtilSelfTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteUtilSelfTestSuite.java
@@ -39,6 +39,7 @@ import org.apache.ignite.spi.discovery.ClusterMetricsSnapshotSerializeSelfTest;
 import org.apache.ignite.testframework.GridTestUtils;
 import org.apache.ignite.thread.GridThreadPoolExecutorServiceSelfTest;
 import org.apache.ignite.thread.IgniteThreadPoolSizeTest;
+import org.apache.ignite.util.GridIntListSelfTest;
 import org.apache.ignite.util.GridLongListSelfTest;
 import org.apache.ignite.util.GridMessageCollectionTest;
 import org.apache.ignite.util.GridQueueSelfTest;
@@ -76,6 +77,7 @@ public class IgniteUtilSelfTestSuite extends TestSuite {
         suite.addTestSuite(GridByteArrayListSelfTest.class);
         suite.addTestSuite(GridMBeanSelfTest.class);
         suite.addTestSuite(GridLongListSelfTest.class);
+        suite.addTestSuite(GridIntListSelfTest.class);
         suite.addTestSuite(GridArraysSelfTest.class);
         suite.addTestSuite(GridCacheUtilsSelfTest.class);
         suite.addTestSuite(IgniteExceptionRegistrySelfTest.class);

http://git-wip-us.apache.org/repos/asf/ignite/blob/d60cf53b/modules/core/src/test/java/org/apache/ignite/util/GridIntListSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/util/GridIntListSelfTest.java b/modules/core/src/test/java/org/apache/ignite/util/GridIntListSelfTest.java
new file mode 100644
index 0000000..cc48fa8
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/util/GridIntListSelfTest.java
@@ -0,0 +1,153 @@
+/*
+ * 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.
+ */
+
+package org.apache.ignite.util;
+
+import junit.framework.TestCase;
+import org.apache.ignite.internal.util.GridIntList;
+
+import static org.apache.ignite.internal.util.GridIntList.asList;
+
+/**
+ *
+ */
+public class GridIntListSelfTest extends TestCase {
+    /**
+     * @throws Exception If failed.
+     */
+    @SuppressWarnings("ZeroLengthArrayAllocation")
+    public void testCopyWithout() throws Exception {
+        assertCopy(
+            new GridIntList(new int[] {}),
+            new GridIntList(new int[] {}));
+
+        assertCopy(
+            new GridIntList(new int[] {}),
+            new GridIntList(new int[] {1}));
+
+        assertCopy(
+            new GridIntList(new int[] {1}),
+            new GridIntList(new int[] {}));
+
+        assertCopy(
+            new GridIntList(new int[] {1, 2, 3}),
+            new GridIntList(new int[] {4, 5, 6}));
+
+        assertCopy(
+            new GridIntList(new int[] {1, 2, 3}),
+            new GridIntList(new int[] {1, 2, 3}));
+
+        assertCopy(
+            new GridIntList(new int[] {1, 2, 3, 4, 5, 1}),
+            new GridIntList(new int[] {1, 1}));
+
+        assertCopy(
+            new GridIntList(new int[] {1, 1, 1, 2, 3, 4, 5, 1, 1, 1}),
+            new GridIntList(new int[] {1, 1}));
+
+        assertCopy(
+            new GridIntList(new int[] {1, 2, 3}),
+            new GridIntList(new int[] {1, 1, 2, 2, 3, 3}));
+    }
+
+    /**
+     *
+     */
+    public void testTruncate() {
+        GridIntList list = asList(1, 2, 3, 4, 5, 6, 7, 8);
+
+        list.truncate(4, true);
+
+        assertEquals(asList(1, 2, 3, 4), list);
+
+        list.truncate(2, false);
+
+        assertEquals(asList(3, 4), list);
+
+        list = new GridIntList();
+
+        list.truncate(0, false);
+        list.truncate(0, true);
+
+        assertEquals(new GridIntList(), list);
+    }
+
+    /**
+     * Assert {@link GridIntList#copyWithout(GridIntList)} on given lists.
+     *
+     * @param lst Source lists.
+     * @param rmv Exclude list.
+     */
+    private void assertCopy(GridIntList lst, GridIntList rmv) {
+        GridIntList res = lst.copyWithout(rmv);
+
+        for (int i = 0; i < lst.size(); i++) {
+            int v = lst.get(i);
+
+            if (rmv.contains(v))
+                assertFalse(res.contains(v));
+            else
+                assertTrue(res.contains(v));
+        }
+    }
+
+    /**
+     *
+     */
+    public void testRemove() {
+        GridIntList list = asList(1, 2, 3, 4, 5, 6);
+
+        assertEquals(2, list.removeValue(0, 3));
+        assertEquals(asList(1, 2, 4, 5, 6), list);
+
+        assertEquals(-1, list.removeValue(1, 1));
+        assertEquals(-1, list.removeValue(0, 3));
+
+        assertEquals(4, list.removeValue(0, 6));
+        assertEquals(asList(1, 2, 4, 5), list);
+
+        assertEquals(2, list.removeIndex(1));
+        assertEquals(asList(1, 4, 5), list);
+
+        assertEquals(1, list.removeIndex(0));
+        assertEquals(asList(4, 5), list);
+    }
+
+    /**
+     *
+     */
+    public void testSort() {
+        assertEquals(new GridIntList(), new GridIntList().sort());
+        assertEquals(asList(1), asList(1).sort());
+        assertEquals(asList(1, 2), asList(2, 1).sort());
+        assertEquals(asList(1, 2, 3), asList(2, 1, 3).sort());
+
+        GridIntList list = new GridIntList();
+
+        list.add(4);
+        list.add(3);
+        list.add(5);
+        list.add(1);
+
+        assertEquals(asList(1, 3, 4, 5), list.sort());
+
+        list.add(0);
+
+        assertEquals(asList(1, 3, 4, 5, 0), list);
+        assertEquals(asList(0, 1, 3, 4, 5), list.sort());
+    }
+}


Mime
View raw message