IGNITE-2706 - Fixed GridHandleTable.lookup()
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/b6f7e63a Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/b6f7e63a Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/b6f7e63a Branch: refs/heads/ignite-2801 Commit: b6f7e63af572c385f280532d9400c60c2827603d Parents: 99bbc72 Author: Valentin Kulichenko <[email protected]> Authored: Mon Feb 22 16:21:15 2016 -0800 Committer: Valentin Kulichenko <[email protected]> Committed: Thu Feb 25 16:57:30 2016 -0800 ---------------------------------------------------------------------- .../ignite/internal/util/GridHandleTable.java | 7 ++- .../internal/util/GridHandleTableSelfTest.java | 50 ++++++++++++++++++++ .../testsuites/IgniteBinaryBasicTestSuite.java | 2 + .../IgniteMarshallerSelfTestSuite.java | 6 ++- 4 files changed, 61 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/b6f7e63a/modules/core/src/main/java/org/apache/ignite/internal/util/GridHandleTable.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/GridHandleTable.java b/modules/core/src/main/java/org/apache/ignite/internal/util/GridHandleTable.java index 319a633..6667a04 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/GridHandleTable.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/GridHandleTable.java @@ -97,9 +97,12 @@ public class GridHandleTable { if (size >= next.length) growEntries(); - if (size >= threshold) + if (size >= threshold) { growSpine(); + idx = hash(obj) % spine.length; + } + insert(obj, size, idx); size++; @@ -194,4 +197,4 @@ public class GridHandleTable { private int hash(Object obj) { return System.identityHashCode(obj) & 0x7FFFFFFF; } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/ignite/blob/b6f7e63a/modules/core/src/test/java/org/apache/ignite/internal/util/GridHandleTableSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/util/GridHandleTableSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/util/GridHandleTableSelfTest.java new file mode 100644 index 0000000..bd6105f --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/util/GridHandleTableSelfTest.java @@ -0,0 +1,50 @@ +/* + * 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.internal.util; + +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; + +/** + * Test for {@link GridHandleTable}. + */ +public class GridHandleTableSelfTest extends GridCommonAbstractTest { + /** + * @throws Exception If failed. + */ + public void testGrow() throws Exception { + GridHandleTable table = new GridHandleTable(8, 2); + + for (int i = 0; i < 16; i++) + assertEquals(-1, table.lookup(i)); + + Object testObj = new Object(); + + assertEquals(-1, table.lookup(testObj)); + + assertEquals(16, table.lookup(testObj)); + + int cnt = 0; + + for (Object obj : table.objects()) { + if (obj == testObj) + cnt++; + } + + assertEquals(1, cnt); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/b6f7e63a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryBasicTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryBasicTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryBasicTestSuite.java index e0c06dc..2aabf4f 100644 --- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryBasicTestSuite.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryBasicTestSuite.java @@ -30,6 +30,7 @@ import org.apache.ignite.internal.processors.cache.IgniteCacheP2pUnmarshallingNe import org.apache.ignite.internal.processors.cache.IgniteCacheP2pUnmarshallingRebalanceErrorTest; import org.apache.ignite.internal.processors.cache.IgniteCacheP2pUnmarshallingTxErrorTest; import org.apache.ignite.internal.processors.cache.IgniteDaemonNodeMarshallerCacheTest; +import org.apache.ignite.internal.util.GridHandleTableSelfTest; import org.apache.ignite.internal.util.GridStartupWithSpecifiedWorkDirectorySelfTest; import org.apache.ignite.internal.util.IgniteUtilsSelfTest; import org.apache.ignite.internal.util.io.GridUnsafeDataOutputArraySizingSelfTest; @@ -86,6 +87,7 @@ public class IgniteBinaryBasicTestSuite extends TestSuite { ignoredTests.add(GridVersionSelfTest.class); ignoredTests.add(GridDeploymentMessageCountSelfTest.class); ignoredTests.add(DynamicProxySerializationMultiJvmSelfTest.class); + ignoredTests.add(GridHandleTableSelfTest.class); // TODO: check and delete if pass. ignoredTests.add(IgniteDaemonNodeMarshallerCacheTest.class); http://git-wip-us.apache.org/repos/asf/ignite/blob/b6f7e63a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteMarshallerSelfTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteMarshallerSelfTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteMarshallerSelfTestSuite.java index 1065fbd..ec0ec23 100644 --- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteMarshallerSelfTestSuite.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteMarshallerSelfTestSuite.java @@ -19,6 +19,7 @@ package org.apache.ignite.testsuites; import java.util.Set; import junit.framework.TestSuite; +import org.apache.ignite.internal.util.GridHandleTableSelfTest; import org.apache.ignite.internal.util.io.GridUnsafeDataOutputArraySizingSelfTest; import org.apache.ignite.marshaller.jdk.GridJdkMarshallerSelfTest; import org.apache.ignite.marshaller.optimized.OptimizedMarshallerEnumSelfTest; @@ -42,7 +43,7 @@ public class IgniteMarshallerSelfTestSuite extends TestSuite { } /** - * @param ignoredTests + * @param ignoredTests Ignored tests. * @return Test suite. * @throws Exception Thrown in case of the failure. */ @@ -57,7 +58,8 @@ public class IgniteMarshallerSelfTestSuite extends TestSuite { GridTestUtils.addTestIfNeeded(suite, GridUnsafeDataOutputArraySizingSelfTest.class, ignoredTests); GridTestUtils.addTestIfNeeded(suite, OptimizedMarshallerNodeFailoverTest.class, ignoredTests); GridTestUtils.addTestIfNeeded(suite, OptimizedMarshallerSerialPersistentFieldsSelfTest.class, ignoredTests); + GridTestUtils.addTestIfNeeded(suite, GridHandleTableSelfTest.class, ignoredTests); return suite; } -} \ No newline at end of file +}
