You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ir...@apache.org on 2019/09/02 16:14:18 UTC
[ignite] branch master updated: IGNITE-12062 IntMap throws
NullPointerException when map is creating - Fixes #6769.
This is an automated email from the ASF dual-hosted git repository.
irakov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push:
new a7834c6 IGNITE-12062 IntMap throws NullPointerException when map is creating - Fixes #6769.
a7834c6 is described below
commit a7834c62d3ad086b4f64f25fb5c926f467225869
Author: mstepachev <ma...@gmail.com>
AuthorDate: Mon Sep 2 19:13:58 2019 +0300
IGNITE-12062 IntMap throws NullPointerException when map is creating - Fixes #6769.
Signed-off-by: Ivan Rakov <ir...@apache.org>
---
.../internal/util/collection/IntHashMap.java | 29 ++++++++++++++--------
.../processors/cache/IgniteCacheGroupsTest.java | 6 ++---
.../internal/util/collection/IntHashMapTest.java | 10 +++++++-
.../ignite/testsuites/IgniteBasicTestSuite.java | 4 +++
4 files changed, 35 insertions(+), 14 deletions(-)
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/collection/IntHashMap.java b/modules/core/src/main/java/org/apache/ignite/internal/util/collection/IntHashMap.java
index ba68056..d6b57d8 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/collection/IntHashMap.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/collection/IntHashMap.java
@@ -72,13 +72,12 @@ public class IntHashMap<V> implements IntMap<V> {
}
}
- /** Default constructor. */
- public IntHashMap() {
- entries = (Entry<V>[])new Entry[INITIAL_CAPACITY];
- }
-
- /** Create map with preallocated array. */
- public IntHashMap(int cap) {
+ /**
+ * Returns required size of table.
+ *
+ * @param cap Capacity.
+ */
+ static int tableSize(int cap) {
int n = cap - 1;
n |= n >>> 1;
n |= n >>> 2;
@@ -86,11 +85,21 @@ public class IntHashMap<V> implements IntMap<V> {
n |= n >>> 8;
n |= n >>> 16;
- int entriesSize = (n < INITIAL_CAPACITY) ? INITIAL_CAPACITY : (n >= MAXIMUM_CAPACITY) ? MAXIMUM_CAPACITY : n + 1;
+ return (n < INITIAL_CAPACITY) ? INITIAL_CAPACITY : (n >= MAXIMUM_CAPACITY) ? MAXIMUM_CAPACITY : n + 1;
+ }
- compactThreshold = (int)(COMPACT_LOAD_FACTOR * (entries.length >> 1));
+ /** Default constructor. */
+ public IntHashMap() {
+ entries = (Entry<V>[])new Entry[INITIAL_CAPACITY];
+ }
- scaleThreshold = (int)(entries.length * SCALE_LOAD_FACTOR);
+ /** Create map with preallocated array. */
+ public IntHashMap(int cap) {
+ int entriesSize = tableSize(cap);
+
+ compactThreshold = (int)(COMPACT_LOAD_FACTOR * (entriesSize >> 1));
+
+ scaleThreshold = (int)(entriesSize * SCALE_LOAD_FACTOR);
entries = (Entry<V>[])new Entry[entriesSize];
}
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheGroupsTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheGroupsTest.java
index 0ab22fd..1e7f580 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheGroupsTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheGroupsTest.java
@@ -81,6 +81,7 @@ import org.apache.ignite.internal.binary.BinaryMarshaller;
import org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition;
import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow;
import org.apache.ignite.internal.processors.platform.cache.expiry.PlatformExpiryPolicyFactory;
+import org.apache.ignite.internal.util.collection.IntMap;
import org.apache.ignite.internal.util.lang.GridAbsPredicate;
import org.apache.ignite.internal.util.lang.GridIterator;
import org.apache.ignite.internal.util.lang.GridPlainCallable;
@@ -4177,12 +4178,11 @@ public class IgniteCacheGroupsTest extends GridCommonAbstractTest {
assertNotNull(grp);
for (GridDhtLocalPartition part : grp.topology().currentLocalPartitions()) {
- Map<Integer, Object> cachesMap = GridTestUtils.getFieldValue(part, "cacheMaps");
+ IntMap<Object> cachesMap = GridTestUtils.getFieldValue(part, "cacheMaps");
assertTrue(cachesMap.size() <= cacheIds.size());
- for (Integer cacheId : cachesMap.keySet())
- assertTrue(cachesMap.containsKey(cacheId));
+ cachesMap.forEach((cacheId, v) -> assertTrue(cachesMap.containsKey(cacheId)));
}
}
}
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/util/collection/IntHashMapTest.java b/modules/core/src/test/java/org/apache/ignite/internal/util/collection/IntHashMapTest.java
index 0af34c9..da84dfc 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/util/collection/IntHashMapTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/util/collection/IntHashMapTest.java
@@ -103,7 +103,15 @@ public class IntHashMapTest extends AbstractBaseIntMapTest {
assertEquals(16, realCapacityForInitialSize(9));
assertEquals(128, realCapacityForInitialSize(99));
assertEquals(256, realCapacityForInitialSize(155));
- assertEquals(MAXIMUM_CAPACITY, realCapacityForInitialSize(Integer.MAX_VALUE));
+ }
+
+ /**
+ *
+ */
+ @Test
+ public void shouldReturnsRequiredTableSizeForCustomCapacity() {
+ assertEquals(INITIAL_CAPACITY, IntHashMap.tableSize(1));
+ assertEquals(MAXIMUM_CAPACITY, IntHashMap.tableSize(Integer.MAX_VALUE));
}
/**
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
index ed9079d..ac8dd15 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
@@ -91,6 +91,8 @@ import org.apache.ignite.internal.product.GridProductVersionSelfTest;
import org.apache.ignite.internal.util.collection.BitSetIntSetTest;
import org.apache.ignite.internal.util.collection.ImmutableIntSetTest;
import org.apache.ignite.internal.util.GridCleanerTest;
+import org.apache.ignite.internal.util.collection.IntHashMapTest;
+import org.apache.ignite.internal.util.collection.IntRWHashMapTest;
import org.apache.ignite.internal.util.nio.IgniteExceptionInNioWorkerSelfTest;
import org.apache.ignite.marshaller.DynamicProxySerializationMultiJvmSelfTest;
import org.apache.ignite.marshaller.MarshallerContextSelfTest;
@@ -201,6 +203,8 @@ import org.junit.runners.Suite;
SwapPathConstructionSelfTest.class,
BitSetIntSetTest.class,
ImmutableIntSetTest.class,
+ IntHashMapTest.class,
+ IntRWHashMapTest.class,
IgniteMarshallerCacheFSRestoreTest.class,
IgniteMarshallerCacheClassNameConflictTest.class,