You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2016/09/29 12:03:03 UTC
[1/8] ignite git commit: Fixed incorrect test count calculation
leading to afterTestsStopped() not being called.
Repository: ignite
Updated Branches:
refs/heads/ignite-3601p 7b0607814 -> 461395cc7
Fixed incorrect test count calculation leading to afterTestsStopped() not being called.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/78144c4c
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/78144c4c
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/78144c4c
Branch: refs/heads/ignite-3601p
Commit: 78144c4c9d6200ceef8b666a186039685f053381
Parents: 33d3494
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Wed Sep 28 16:52:13 2016 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Wed Sep 28 16:52:13 2016 +0300
----------------------------------------------------------------------
.../ignite/testframework/IgniteTestSuite.java | 79 +++++++++++++++++---
.../testframework/junits/GridAbstractTest.java | 31 +++++++-
2 files changed, 94 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/78144c4c/modules/core/src/test/java/org/apache/ignite/testframework/IgniteTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/IgniteTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testframework/IgniteTestSuite.java
index 7db9664..1cf69ae 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/IgniteTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/IgniteTestSuite.java
@@ -29,6 +29,7 @@ import org.junit.internal.MethodSorter;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
+import java.util.LinkedList;
import java.util.List;
/**
@@ -134,7 +135,9 @@ public class IgniteTestSuite extends TestSuite {
Class superCls = theClass;
int testAdded = 0;
- int testIgnored = 0;
+ int testSkipped = 0;
+
+ LinkedList<Test> addedTests = new LinkedList<>();
for(List<String> names = new ArrayList<>(); Test.class.isAssignableFrom(superCls);
superCls = superCls.getSuperclass()) {
@@ -142,15 +145,29 @@ public class IgniteTestSuite extends TestSuite {
Method[] methods = MethodSorter.getDeclaredMethods(superCls);
for (Method each : methods) {
- if (addTestMethod(each, names, theClass, clsIgnore))
+ AddResult res = addTestMethod(each, names, theClass, clsIgnore);
+
+ if (res.added()) {
testAdded++;
+
+ addedTests.add(res.test());
+ }
else
- testIgnored++;
+ testSkipped++;
}
}
- if(testAdded == 0 && testIgnored == 0)
+ if(testAdded == 0 && testSkipped == 0)
addTest(warning("No tests found in " + theClass.getName()));
+
+ // Populate tests count.
+ for (Test test : addedTests) {
+ if (test instanceof GridAbstractTest) {
+ GridAbstractTest test0 = (GridAbstractTest)test;
+
+ test0.forceTestCount(addedTests.size());
+ }
+ }
}
}
@@ -161,20 +178,20 @@ public class IgniteTestSuite extends TestSuite {
* @param names Test name list.
* @param theClass Test class.
* @param clsIgnore Class ignore descriptor (if any).
- * @return Whether test method was added.
+ * @return Result.
*/
- private boolean addTestMethod(Method m, List<String> names, Class<?> theClass,
+ private AddResult addTestMethod(Method m, List<String> names, Class<?> theClass,
@Nullable IgnoreDescriptor clsIgnore) {
String name = m.getName();
if (names.contains(name))
- return false;
+ return new AddResult(false, null);
if (!isPublicTestMethod(m)) {
if (isTestMethod(m))
addTest(warning("Test method isn't public: " + m.getName() + "(" + theClass.getCanonicalName() + ")"));
- return false;
+ return new AddResult(false, null);
}
names.add(name);
@@ -197,18 +214,20 @@ public class IgniteTestSuite extends TestSuite {
addTest(test);
- return true;
+ return new AddResult(true, test);
}
}
else {
if (ignore == null) {
- addTest(createTest(theClass, name));
+ Test test = createTest(theClass, name);
+
+ addTest(test);
- return true;
+ return new AddResult(true, test);
}
}
- return false;
+ return new AddResult(false, null);
}
/**
@@ -337,6 +356,42 @@ public class IgniteTestSuite extends TestSuite {
}
/**
+ * Test add result.
+ */
+ private static class AddResult {
+ /** Result. */
+ private final boolean added;
+
+ /** Test */
+ private final Test test;
+
+ /**
+ * Constructor.
+ *
+ * @param added Result.
+ * @param test Test.
+ */
+ public AddResult(boolean added, Test test) {
+ this.added = added;
+ this.test = test;
+ }
+
+ /**
+ * @return Result.
+ */
+ public boolean added() {
+ return added;
+ }
+
+ /**
+ * @return Test.
+ */
+ public Test test() {
+ return test;
+ }
+ }
+
+ /**
* Test case simulating failure.
*/
private static class ForcedFailure extends TestCase {
http://git-wip-us.apache.org/repos/asf/ignite/blob/78144c4c/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java
index 8d6fd07..aa90af0 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java
@@ -161,6 +161,12 @@ public abstract class GridAbstractTest extends TestCase {
/** Force failure message. */
private String forceFailureMsg;
+ /** Whether test count is known is advance. */
+ private boolean forceTestCnt;
+
+ /** Number of tests. */
+ private int testCnt;
+
/**
*
*/
@@ -1770,6 +1776,15 @@ public abstract class GridAbstractTest extends TestCase {
}
/**
+ * Set test count.
+ */
+ public void forceTestCount(int cnt) {
+ testCnt = cnt;
+
+ forceTestCnt = true;
+ }
+
+ /**
* @throws Throwable If failed.
*/
@SuppressWarnings({"ProhibitedExceptionDeclared"})
@@ -2076,11 +2091,19 @@ public abstract class GridAbstractTest extends TestCase {
*/
public int getNumberOfTests() {
if (numOfTests == -1) {
- int cnt = 0;
+ GridAbstractTest this0 = GridAbstractTest.this;
+
+ int cnt;
- for (Method m : GridAbstractTest.this.getClass().getMethods())
- if (m.getName().startsWith("test") && Modifier.isPublic(m.getModifiers()))
- cnt++;
+ if (this0.forceTestCnt)
+ cnt = this0.testCnt;
+ else {
+ cnt = 0;
+
+ for (Method m : this0.getClass().getMethods())
+ if (m.getName().startsWith("test") && Modifier.isPublic(m.getModifiers()))
+ cnt++;
+ }
numOfTests = cnt;
}
[8/8] ignite git commit: Merge remote-tracking branch
'remotes/community/ignite-1.6.9' into ignite-3601p
Posted by sb...@apache.org.
Merge remote-tracking branch 'remotes/community/ignite-1.6.9' into ignite-3601p
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/461395cc
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/461395cc
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/461395cc
Branch: refs/heads/ignite-3601p
Commit: 461395cc7be1db7be8f348922b4d68416b4d624b
Parents: 7b06078 ad613af
Author: sboikov <sb...@gridgain.com>
Authored: Thu Sep 29 15:02:46 2016 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Thu Sep 29 15:02:46 2016 +0300
----------------------------------------------------------------------
.../internal/binary/BinaryClassDescriptor.java | 32 ++++--
.../internal/binary/BinaryEnumObjectImpl.java | 5 +
.../ignite/internal/binary/BinaryObjectEx.java | 8 ++
.../internal/binary/BinaryObjectImpl.java | 7 ++
.../binary/BinaryObjectOffheapImpl.java | 7 ++
.../ignite/internal/binary/BinaryUtils.java | 5 +-
.../internal/binary/BinaryWriterExImpl.java | 6 +-
.../binary/builder/BinaryObjectBuilderImpl.java | 35 +++---
.../processors/cache/GridCacheAdapter.java | 7 ++
.../processors/cache/GridCacheUtils.java | 5 +
.../ignite/internal/util/IgniteUtils.java | 23 +++-
.../binary/BinaryFieldOrderSelfTest.java | 115 +++++++++++++++++++
...ridCacheStoreManagerDeserializationTest.java | 1 +
.../cache/GridCacheUtilsSelfTest.java | 64 ++++++++++-
...calCacheStoreManagerDeserializationTest.java | 2 +-
.../IgniteCacheConfigVariationsFullApiTest.java | 7 +-
...niteCacheExpireAndUpdateConsistencyTest.java | 7 ++
.../GridCacheBinaryObjectsAbstractSelfTest.java | 37 ++++++
.../ignite/testframework/IgniteTestSuite.java | 79 +++++++++++--
.../testframework/junits/GridAbstractTest.java | 31 ++++-
.../IgniteBinaryObjectsTestSuite.java | 2 +
21 files changed, 440 insertions(+), 45 deletions(-)
----------------------------------------------------------------------
[7/8] ignite git commit: ignite-3621 Fixed 'testEvictExpired'.
Posted by sb...@apache.org.
ignite-3621 Fixed 'testEvictExpired'.
(cherry picked from commit a4d7aa3)
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/ad613afd
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/ad613afd
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/ad613afd
Branch: refs/heads/ignite-3601p
Commit: ad613afd7165ed2d8bf0a62805fc2506dfe6c59a
Parents: 062b9b6
Author: sboikov <sb...@gridgain.com>
Authored: Thu Sep 29 12:04:44 2016 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Thu Sep 29 14:16:31 2016 +0300
----------------------------------------------------------------------
.../cache/IgniteCacheConfigVariationsFullApiTest.java | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/ad613afd/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheConfigVariationsFullApiTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheConfigVariationsFullApiTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheConfigVariationsFullApiTest.java
index 2ca09c8..6b0e193 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheConfigVariationsFullApiTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheConfigVariationsFullApiTest.java
@@ -3336,7 +3336,12 @@ public class IgniteCacheConfigVariationsFullApiTest extends IgniteCacheConfigVar
boolean wait = waitForCondition(new GridAbsPredicate() {
@Override public boolean apply() {
- return cache.localPeek(key) == null;
+ for (int i = 0; i < gridCount(); i++) {
+ if (peek(jcache(i), key) != null)
+ return false;
+ }
+
+ return true;
}
}, ttl + 1000);
[6/8] ignite git commit: IGNITE-3633 - Enforce key validation for
tests.
Posted by sb...@apache.org.
IGNITE-3633 - Enforce key validation for tests.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/062b9b69
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/062b9b69
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/062b9b69
Branch: refs/heads/ignite-3601p
Commit: 062b9b69aa851d5253dfb7f44066b7d749f1ca12
Parents: 3e8a1c6
Author: Alexey Goncharuk <al...@gmail.com>
Authored: Thu Sep 29 11:26:50 2016 +0300
Committer: Alexey Goncharuk <al...@gmail.com>
Committed: Thu Sep 29 11:27:43 2016 +0300
----------------------------------------------------------------------
.../ignite/internal/processors/cache/GridCacheAdapter.java | 7 +++++++
.../cache/binary/GridCacheBinaryObjectsAbstractSelfTest.java | 6 ++++++
2 files changed, 13 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/062b9b69/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
index fe6bb1b..55400ab 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
@@ -4891,6 +4891,13 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
}
/**
+ * For tests only.
+ */
+ public void forceKeyCheck() {
+ keyCheck = true;
+ }
+
+ /**
* Validates that given cache key has overridden equals and hashCode methods and
* implements {@link Externalizable}.
*
http://git-wip-us.apache.org/repos/asf/ignite/blob/062b9b69/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectsAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectsAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectsAbstractSelfTest.java
index 7936ea4..150c245 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectsAbstractSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectsAbstractSelfTest.java
@@ -894,6 +894,10 @@ public abstract class GridCacheBinaryObjectsAbstractSelfTest extends GridCommonA
public void testPutWithoutHashCode() throws Exception {
final IgniteCache c = jcache(0);
+ GridCacheAdapter<Object, Object> cache0 = grid(0).context().cache().internalCache(null);
+
+ cache0.forceKeyCheck();
+
GridTestUtils.assertThrows(log, new Callable<Object>() {
/** {@inheritDoc} */
@Override public Object call() throws Exception {
@@ -907,6 +911,8 @@ public abstract class GridCacheBinaryObjectsAbstractSelfTest extends GridCommonA
final BinaryObject binKey = bldr.build();
+ cache0.forceKeyCheck();
+
GridTestUtils.assertThrows(log, new Callable<Object>() {
/** {@inheritDoc} */
@Override public Object call() throws Exception {
[4/8] ignite git commit: Fixed missing Apache header.
Posted by sb...@apache.org.
Fixed missing Apache header.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/b280c3ef
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/b280c3ef
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/b280c3ef
Branch: refs/heads/ignite-3601p
Commit: b280c3efa1eb84c6bc8abbe31ba669b0c24323d8
Parents: d1e3a78
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Thu Sep 29 10:23:54 2016 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Thu Sep 29 10:23:54 2016 +0300
----------------------------------------------------------------------
.../internal/binary/BinaryFieldOrderSelfTest.java | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/b280c3ef/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFieldOrderSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFieldOrderSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFieldOrderSelfTest.java
index 6bb1e13..e470948 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFieldOrderSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFieldOrderSelfTest.java
@@ -1,3 +1,20 @@
+/*
+ * 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.binary;
import org.apache.ignite.binary.BinaryObject;
[3/8] ignite git commit: IGNITE-3191 - Fixed ordering of fields in
binary objects
Posted by sb...@apache.org.
IGNITE-3191 - Fixed ordering of fields in binary objects
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/d1e3a78a
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/d1e3a78a
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/d1e3a78a
Branch: refs/heads/ignite-3601p
Commit: d1e3a78ae569fa5d5692816db44f2c677e1b8283
Parents: e3dfdec
Author: Valentin Kulichenko <va...@gmail.com>
Authored: Wed Sep 28 17:53:42 2016 -0700
Committer: Valentin Kulichenko <va...@gmail.com>
Committed: Wed Sep 28 17:53:42 2016 -0700
----------------------------------------------------------------------
.../internal/binary/BinaryClassDescriptor.java | 16 ++--
.../binary/builder/BinaryObjectBuilderImpl.java | 24 ++---
.../binary/BinaryFieldOrderSelfTest.java | 98 ++++++++++++++++++++
.../IgniteBinaryObjectsTestSuite.java | 2 +
4 files changed, 121 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/d1e3a78a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java
index 4c824d4..276dfe5 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java
@@ -25,7 +25,6 @@ import java.lang.reflect.Modifier;
import java.lang.reflect.Proxy;
import java.math.BigDecimal;
import java.sql.Timestamp;
-import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
@@ -33,6 +32,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+import java.util.TreeMap;
import java.util.UUID;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.binary.BinaryObjectException;
@@ -269,10 +269,9 @@ public class BinaryClassDescriptor {
case OBJECT:
// Must not use constructor to honor transient fields semantics.
ctor = null;
- ArrayList<BinaryFieldAccessor> fields0 = new ArrayList<>();
stableFieldsMeta = metaDataEnabled ? new HashMap<String, Integer>() : null;
- BinarySchema.Builder schemaBuilder = BinarySchema.Builder.newBuilder();
+ Map<String, BinaryFieldAccessor> fields0 = new TreeMap<>();
Set<String> duplicates = duplicateFields(cls);
@@ -300,9 +299,7 @@ public class BinaryClassDescriptor {
BinaryFieldAccessor fieldInfo = BinaryFieldAccessor.create(f, fieldId);
- fields0.add(fieldInfo);
-
- schemaBuilder.addField(fieldId);
+ fields0.put(name, fieldInfo);
if (metaDataEnabled)
stableFieldsMeta.put(name, fieldInfo.mode().typeId());
@@ -310,7 +307,12 @@ public class BinaryClassDescriptor {
}
}
- fields = fields0.toArray(new BinaryFieldAccessor[fields0.size()]);
+ fields = fields0.values().toArray(new BinaryFieldAccessor[fields0.size()]);
+
+ BinarySchema.Builder schemaBuilder = BinarySchema.Builder.newBuilder();
+
+ for (BinaryFieldAccessor field : fields)
+ schemaBuilder.addField(field.id);
stableSchema = schemaBuilder.build();
http://git-wip-us.apache.org/repos/asf/ignite/blob/d1e3a78a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java
index 2c76192..d166051 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java
@@ -17,32 +17,32 @@
package org.apache.ignite.internal.binary.builder;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
import org.apache.ignite.binary.BinaryInvalidTypeException;
import org.apache.ignite.binary.BinaryObject;
import org.apache.ignite.binary.BinaryObjectBuilder;
import org.apache.ignite.binary.BinaryObjectException;
import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.internal.binary.BinaryContext;
import org.apache.ignite.internal.binary.BinaryMetadata;
import org.apache.ignite.internal.binary.BinaryObjectImpl;
-import org.apache.ignite.internal.binary.BinaryWriterExImpl;
-import org.apache.ignite.internal.binary.GridBinaryMarshaller;
-import org.apache.ignite.internal.binary.BinaryContext;
+import org.apache.ignite.internal.binary.BinaryObjectOffheapImpl;
import org.apache.ignite.internal.binary.BinarySchema;
import org.apache.ignite.internal.binary.BinarySchemaRegistry;
-import org.apache.ignite.internal.binary.BinaryObjectOffheapImpl;
import org.apache.ignite.internal.binary.BinaryUtils;
+import org.apache.ignite.internal.binary.BinaryWriterExImpl;
+import org.apache.ignite.internal.binary.GridBinaryMarshaller;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.lang.IgniteBiTuple;
import org.jetbrains.annotations.Nullable;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Set;
-
/**
*
*/
@@ -522,7 +522,7 @@ public class BinaryObjectBuilderImpl implements BinaryObjectBuilder {
Object val = val0 == null ? new BinaryValueWithType(BinaryUtils.typeByClass(Object.class), null) : val0;
if (assignedVals == null)
- assignedVals = new LinkedHashMap<>();
+ assignedVals = new TreeMap<>();
Object oldVal = assignedVals.put(name, val);
http://git-wip-us.apache.org/repos/asf/ignite/blob/d1e3a78a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFieldOrderSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFieldOrderSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFieldOrderSelfTest.java
new file mode 100644
index 0000000..6bb1e13
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFieldOrderSelfTest.java
@@ -0,0 +1,98 @@
+package org.apache.ignite.internal.binary;
+
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+/**
+ * Test that field ordering doesn't change the schema.
+ */
+public class BinaryFieldOrderSelfTest extends GridCommonAbstractTest {
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ cfg.setMarshaller(new BinaryMarshaller());
+ cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(new TcpDiscoveryVmIpFinder(true)));
+
+ return cfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTest() throws Exception {
+ startGrid();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ stopAllGrids();
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testEquals() throws Exception {
+ IgniteEx ignite = grid();
+
+ BinaryObject bo0 = ignite.binary().toBinary(new MyType(222, 333, 111));
+
+ BinaryObject bo1 = ignite.binary().builder(bo0.type().typeName()).
+ setField("b", 222).
+ setField("c", 333).
+ setField("a", 111).
+ hashCode(12345).
+ build();
+
+ BinaryObject bo2 = ignite.binary().builder(bo0.type().typeName()).
+ setField("a", 111).
+ setField("b", 222).
+ setField("c", 333).
+ hashCode(12345).
+ build();
+
+ assertEquals(12345, bo0.hashCode());
+ assertEquals(12345, bo1.hashCode());
+ assertEquals(12345, bo2.hashCode());
+
+ assertTrue(bo0.equals(bo1));
+ assertTrue(bo0.equals(bo2));
+ assertTrue(bo1.equals(bo2));
+ }
+
+ /**
+ */
+ private static class MyType {
+ /** B. */
+ private int b;
+
+ /** C. */
+ private int c;
+
+ /** A. */
+ private int a;
+
+ /**
+ * @param b B.
+ * @param c C.
+ * @param a A.
+ */
+ MyType(int b, int c, int a) {
+ this.b = b;
+ this.c = c;
+ this.a = a;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object obj) {
+ return super.equals(obj);
+ }
+
+ /** {@inheritDoc} */
+ @Override public int hashCode() {
+ return 12345;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/d1e3a78a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsTestSuite.java
index c1d9974..50c6f0b 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsTestSuite.java
@@ -22,6 +22,7 @@ import org.apache.ignite.internal.binary.BinaryBasicIdMapperSelfTest;
import org.apache.ignite.internal.binary.BinaryBasicNameMapperSelfTest;
import org.apache.ignite.internal.binary.BinaryConfigurationConsistencySelfTest;
import org.apache.ignite.internal.binary.BinaryEnumsSelfTest;
+import org.apache.ignite.internal.binary.BinaryFieldOrderSelfTest;
import org.apache.ignite.internal.binary.BinaryFieldsHeapSelfTest;
import org.apache.ignite.internal.binary.BinaryFieldsOffheapSelfTest;
import org.apache.ignite.internal.binary.BinaryFooterOffsetsHeapSelfTest;
@@ -104,6 +105,7 @@ public class IgniteBinaryObjectsTestSuite extends TestSuite {
suite.addTestSuite(GridBinaryAffinityKeySelfTest.class);
suite.addTestSuite(GridBinaryWildcardsSelfTest.class);
suite.addTestSuite(BinaryObjectToStringSelfTest.class);
+ suite.addTestSuite(BinaryFieldOrderSelfTest.class);
// Tests for objects with non-compact footers.
suite.addTestSuite(BinaryMarshallerNonCompactSelfTest.class);
[2/8] ignite git commit: Validate hash code presence in BinaryObject.
Fixes #928
Posted by sb...@apache.org.
Validate hash code presence in BinaryObject. Fixes #928
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/e3dfdecc
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/e3dfdecc
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/e3dfdecc
Branch: refs/heads/ignite-3601p
Commit: e3dfdecc3607b5f3183bfcb1ce36c57543a8965f
Parents: 78144c4
Author: Alexander Paschenko <al...@gmail.com>
Authored: Wed Sep 28 16:46:46 2016 +0300
Committer: Alexey Goncharuk <al...@gmail.com>
Committed: Wed Sep 28 17:00:45 2016 +0300
----------------------------------------------------------------------
.../internal/binary/BinaryClassDescriptor.java | 16 ++++-
.../internal/binary/BinaryEnumObjectImpl.java | 5 ++
.../ignite/internal/binary/BinaryObjectEx.java | 8 +++
.../internal/binary/BinaryObjectImpl.java | 7 +++
.../binary/BinaryObjectOffheapImpl.java | 7 +++
.../ignite/internal/binary/BinaryUtils.java | 5 +-
.../internal/binary/BinaryWriterExImpl.java | 6 +-
.../binary/builder/BinaryObjectBuilderImpl.java | 11 +++-
.../processors/cache/GridCacheUtils.java | 5 ++
.../ignite/internal/util/IgniteUtils.java | 23 ++++++-
...ridCacheStoreManagerDeserializationTest.java | 1 +
.../cache/GridCacheUtilsSelfTest.java | 64 +++++++++++++++++++-
...calCacheStoreManagerDeserializationTest.java | 2 +-
.../GridCacheBinaryObjectsAbstractSelfTest.java | 31 ++++++++++
14 files changed, 182 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/e3dfdecc/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java
index 083057d..4c824d4 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java
@@ -41,6 +41,7 @@ import org.apache.ignite.binary.BinarySerializer;
import org.apache.ignite.binary.Binarylizable;
import org.apache.ignite.internal.processors.cache.CacheObjectImpl;
import org.apache.ignite.internal.util.GridUnsafe;
+import org.apache.ignite.internal.util.IgniteUtils;
import org.apache.ignite.internal.util.tostring.GridToStringExclude;
import org.apache.ignite.internal.util.typedef.internal.S;
import org.apache.ignite.internal.util.typedef.internal.U;
@@ -114,6 +115,9 @@ public class BinaryClassDescriptor {
private final boolean excluded;
/** */
+ private final boolean overridesHashCode;
+
+ /** */
private final Class<?>[] intfs;
/**
@@ -164,6 +168,8 @@ public class BinaryClassDescriptor {
this.mapper = mapper;
this.registered = registered;
+ overridesHashCode = IgniteUtils.overridesEqualsAndHashCode(cls);
+
schemaReg = ctx.schemaRegistry(typeId);
excluded = MarshallerExclusions.isExcluded(cls);
@@ -845,7 +851,15 @@ public class BinaryClassDescriptor {
* @param obj Object.
*/
private void postWrite(BinaryWriterExImpl writer, Object obj) {
- writer.postWrite(userType, registered, obj instanceof CacheObjectImpl ? 0 : obj.hashCode());
+ if (obj instanceof CacheObjectImpl)
+ writer.postWrite(userType, registered, 0, false);
+ else if (obj instanceof BinaryObjectEx) {
+ boolean flagSet = ((BinaryObjectEx)obj).isFlagSet(BinaryUtils.FLAG_EMPTY_HASH_CODE);
+
+ writer.postWrite(userType, registered, obj.hashCode(), !flagSet);
+ }
+ else
+ writer.postWrite(userType, registered, obj.hashCode(), overridesHashCode);
}
/**
http://git-wip-us.apache.org/repos/asf/ignite/blob/e3dfdecc/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryEnumObjectImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryEnumObjectImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryEnumObjectImpl.java
index c9874ed..dcfcc9d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryEnumObjectImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryEnumObjectImpl.java
@@ -139,6 +139,11 @@ public class BinaryEnumObjectImpl implements BinaryObjectEx, Externalizable, Cac
}
/** {@inheritDoc} */
+ @Override public boolean isFlagSet(short flag) {
+ return false;
+ }
+
+ /** {@inheritDoc} */
@Override public <F> F field(String fieldName) throws BinaryObjectException {
return null;
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e3dfdecc/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectEx.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectEx.java
index e3566bc..4e137b7 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectEx.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectEx.java
@@ -38,4 +38,12 @@ public interface BinaryObjectEx extends BinaryObject {
* @throws BinaryObjectException If failed.
*/
@Nullable public BinaryType rawType() throws BinaryObjectException;
+
+ /**
+ * Check if flag set.
+ *
+ * @param flag flag to check.
+ * @return {@code true} if flag is set, {@code false} otherwise.
+ */
+ public boolean isFlagSet(short flag);
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e3dfdecc/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
index 7b42c03..f37d7c2 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
@@ -246,6 +246,13 @@ public final class BinaryObjectImpl extends BinaryObjectExImpl implements Extern
}
/** {@inheritDoc} */
+ @Override public boolean isFlagSet(short flag) {
+ short flags = BinaryPrimitives.readShort(arr, start + GridBinaryMarshaller.FLAGS_POS);
+
+ return BinaryUtils.isFlagSet(flags, flag);
+ }
+
+ /** {@inheritDoc} */
@Override public int typeId() {
int off = start + GridBinaryMarshaller.TYPE_ID_POS;
http://git-wip-us.apache.org/repos/asf/ignite/blob/e3dfdecc/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java
index 2225b7a..9cbbaa2 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java
@@ -145,6 +145,13 @@ public class BinaryObjectOffheapImpl extends BinaryObjectExImpl implements Exter
}
/** {@inheritDoc} */
+ @Override public boolean isFlagSet(short flag) {
+ short flags = BinaryPrimitives.readShort(ptr, start + GridBinaryMarshaller.FLAGS_POS);
+
+ return BinaryUtils.isFlagSet(flags, flag);
+ }
+
+ /** {@inheritDoc} */
@Nullable @Override public BinaryType type() throws BinaryObjectException {
return BinaryUtils.typeProxy(ctx, this);
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e3dfdecc/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java
index b5834a5..25d87ff 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java
@@ -109,6 +109,9 @@ public class BinaryUtils {
/** Flag: compact footer, no field IDs. */
public static final short FLAG_COMPACT_FOOTER = 0x0020;
+ /** Flag: no hash code has been set. */
+ public static final short FLAG_EMPTY_HASH_CODE = 0x0040;
+
/** Offset which fits into 1 byte. */
public static final int OFFSET_1 = 1;
@@ -305,7 +308,7 @@ public class BinaryUtils {
* @param flag Flag.
* @return {@code True} if flag is set in flags.
*/
- private static boolean isFlagSet(short flags, short flag) {
+ static boolean isFlagSet(short flags, short flag) {
return (flags & flag) == flag;
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e3dfdecc/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterExImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterExImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterExImpl.java
index 1a81819..22b4d1f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterExImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterExImpl.java
@@ -245,8 +245,9 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
* @param userType User type flag.
* @param registered Whether type is registered.
* @param hashCode Hash code.
+ * @param isHashCodeSet Hash code presence flag.
*/
- public void postWrite(boolean userType, boolean registered, int hashCode) {
+ public void postWrite(boolean userType, boolean registered, int hashCode, boolean isHashCodeSet) {
short flags;
boolean useCompactFooter;
@@ -303,6 +304,9 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
}
}
+ if (!isHashCodeSet)
+ flags |= BinaryUtils.FLAG_EMPTY_HASH_CODE;
+
// Actual write.
int retPos = out.position();
http://git-wip-us.apache.org/repos/asf/ignite/blob/e3dfdecc/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java
index 086da5c..2c76192 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java
@@ -86,6 +86,9 @@ public class BinaryObjectBuilderImpl implements BinaryObjectBuilder {
/** */
private int hashCode;
+ /** */
+ private boolean isHashCodeSet;
+
/**
* @param clsName Class name.
* @param ctx Binary context.
@@ -117,7 +120,7 @@ public class BinaryObjectBuilderImpl implements BinaryObjectBuilder {
*/
public BinaryObjectBuilderImpl(BinaryObjectImpl obj) {
this(new BinaryBuilderReader(obj), obj.start());
-
+ isHashCodeSet = !obj.isFlagSet(BinaryUtils.FLAG_EMPTY_HASH_CODE);
reader.registerObject(this);
}
@@ -329,7 +332,8 @@ public class BinaryObjectBuilderImpl implements BinaryObjectBuilder {
reader.position(start + BinaryUtils.length(reader, start));
}
- writer.postWrite(true, registeredType, hashCode);
+ //noinspection NumberEquality
+ writer.postWrite(true, registeredType, hashCode, isHashCodeSet);
// Update metadata if needed.
int schemaId = writer.schemaId();
@@ -408,9 +412,12 @@ public class BinaryObjectBuilderImpl implements BinaryObjectBuilder {
}
/** {@inheritDoc} */
+ @SuppressWarnings("UnnecessaryBoxing")
@Override public BinaryObjectBuilderImpl hashCode(int hashCode) {
this.hashCode = hashCode;
+ isHashCodeSet = true;
+
return this;
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e3dfdecc/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
index 1a4ffd5..0f4e89b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
@@ -1170,6 +1170,7 @@ public class GridCacheUtils {
/**
* Validates that cache key object has overridden equals and hashCode methods.
+ * Will also check that a BinaryObject has a hash code set.
*
* @param key Key.
* @throws IllegalArgumentException If equals or hashCode is not implemented.
@@ -1181,6 +1182,10 @@ public class GridCacheUtils {
if (!U.overridesEqualsAndHashCode(key))
throw new IllegalArgumentException("Cache key must override hashCode() and equals() methods: " +
key.getClass().getName());
+
+ if (U.isHashCodeEmpty(key))
+ throw new IllegalArgumentException("Cache key created with BinaryBuilder is missing hash code - " +
+ "please set it explicitly during building by using BinaryBuilder.hashCode(int)");
}
/**
http://git-wip-us.apache.org/repos/asf/ignite/blob/e3dfdecc/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
index cdaeab1..501cdb2 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
@@ -149,6 +149,7 @@ import org.apache.ignite.IgniteException;
import org.apache.ignite.IgniteInterruptedException;
import org.apache.ignite.IgniteLogger;
import org.apache.ignite.IgniteSystemProperties;
+import org.apache.ignite.binary.BinaryObject;
import org.apache.ignite.binary.BinaryRawReader;
import org.apache.ignite.binary.BinaryRawWriter;
import org.apache.ignite.cluster.ClusterGroupEmptyException;
@@ -170,6 +171,8 @@ import org.apache.ignite.internal.IgniteFutureTimeoutCheckedException;
import org.apache.ignite.internal.IgniteInternalFuture;
import org.apache.ignite.internal.IgniteInterruptedCheckedException;
import org.apache.ignite.internal.IgniteNodeAttributes;
+import org.apache.ignite.internal.binary.BinaryObjectEx;
+import org.apache.ignite.internal.binary.BinaryUtils;
import org.apache.ignite.internal.cluster.ClusterGroupEmptyCheckedException;
import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException;
import org.apache.ignite.internal.compute.ComputeTaskCancelledCheckedException;
@@ -8479,9 +8482,15 @@ public abstract class IgniteUtils {
* @return {@code True} if given object has overridden equals and hashCode method.
*/
public static boolean overridesEqualsAndHashCode(Object obj) {
- try {
- Class<?> cls = obj.getClass();
+ return overridesEqualsAndHashCode(obj.getClass());
+ }
+ /**
+ * @param cls Class.
+ * @return {@code True} if given class has overridden equals and hashCode method.
+ */
+ public static boolean overridesEqualsAndHashCode(Class<?> cls) {
+ try {
return !Object.class.equals(cls.getMethod("equals", Object.class).getDeclaringClass()) &&
!Object.class.equals(cls.getMethod("hashCode").getDeclaringClass());
}
@@ -8491,6 +8500,16 @@ public abstract class IgniteUtils {
}
/**
+ * @param obj Object.
+ * @return {@code True} if given object is a {@link BinaryObjectEx} and
+ * has {@link BinaryUtils#FLAG_EMPTY_HASH_CODE} set
+ */
+ public static boolean isHashCodeEmpty(Object obj) {
+ return obj != null && obj instanceof BinaryObjectEx &&
+ ((BinaryObjectEx)obj).isFlagSet(BinaryUtils.FLAG_EMPTY_HASH_CODE);
+ }
+
+ /**
* Checks if error is MAC invalid argument error which ususally requires special handling.
*
* @param e Exception.
http://git-wip-us.apache.org/repos/asf/ignite/blob/e3dfdecc/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheStoreManagerDeserializationTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheStoreManagerDeserializationTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheStoreManagerDeserializationTest.java
index 4a069a9..39ce33d 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheStoreManagerDeserializationTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheStoreManagerDeserializationTest.java
@@ -279,6 +279,7 @@ public class GridCacheStoreManagerDeserializationTest extends GridCommonAbstract
for (int i = 0; i < 1; i++) {
builder.setField("id", i);
+ builder.hashCode(i);
entity = builder.build();
http://git-wip-us.apache.org/repos/asf/ignite/blob/e3dfdecc/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheUtilsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheUtilsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheUtilsSelfTest.java
index d5888e7..5f2c004 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheUtilsSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheUtilsSelfTest.java
@@ -18,7 +18,21 @@
package org.apache.ignite.internal.processors.cache;
import java.util.concurrent.Callable;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.configuration.BinaryConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.binary.BinaryCachingMetadataHandler;
+import org.apache.ignite.internal.binary.BinaryContext;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+import org.apache.ignite.internal.binary.BinaryObjectImpl;
+import org.apache.ignite.internal.binary.GridBinaryMarshaller;
+import org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl;
+import org.apache.ignite.internal.util.IgniteUtils;
import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.logger.NullLogger;
+import org.apache.ignite.marshaller.MarshallerContextTestImpl;
import org.apache.ignite.testframework.GridTestUtils;
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
@@ -104,7 +118,8 @@ public class GridCacheUtilsSelfTest extends GridCommonAbstractTest {
/**
*/
- public void testCacheKeyValidation() {
+ @SuppressWarnings("ResultOfMethodCallIgnored")
+ public void testCacheKeyValidation() throws IgniteCheckedException {
CU.validateCacheKey("key");
CU.validateCacheKey(1);
@@ -124,6 +139,53 @@ public class GridCacheUtilsSelfTest extends GridCommonAbstractTest {
assertThrowsForInvalidKey(new NoHashCode());
assertThrowsForInvalidKey(new WrongEquals());
+
+ BinaryObjectBuilderImpl binBuilder = new BinaryObjectBuilderImpl(binaryContext(),
+ EqualsAndHashCode.class.getName());
+
+ assertThrowsForInvalidKey(binBuilder.build());
+
+ binBuilder.hashCode(0xFE12);
+
+ BinaryObject binObj = binBuilder.build();
+
+ CU.validateCacheKey(binObj);
+
+ BinaryObjectBuilderImpl binBuilder2 = new BinaryObjectBuilderImpl((BinaryObjectImpl) binObj);
+
+ CU.validateCacheKey(binBuilder2.build());
+ }
+
+ /**
+ * @return Binary marshaller.
+ * @throws IgniteCheckedException if failed.
+ */
+ private BinaryMarshaller binaryMarshaller() throws IgniteCheckedException {
+ IgniteConfiguration iCfg = new IgniteConfiguration();
+
+ BinaryConfiguration bCfg = new BinaryConfiguration();
+
+ iCfg.setBinaryConfiguration(bCfg);
+
+ BinaryContext ctx = new BinaryContext(BinaryCachingMetadataHandler.create(), iCfg, new NullLogger());
+
+ BinaryMarshaller marsh = new BinaryMarshaller();
+
+ marsh.setContext(new MarshallerContextTestImpl(null));
+
+ IgniteUtils.invoke(BinaryMarshaller.class, marsh, "setBinaryContext", ctx, iCfg);
+
+ return marsh;
+ }
+
+ /**
+ * @return Binary context.
+ * @throws IgniteCheckedException if failed.
+ */
+ private BinaryContext binaryContext() throws IgniteCheckedException {
+ GridBinaryMarshaller impl = U.field(binaryMarshaller(), "impl");
+
+ return impl.context();
}
/**
http://git-wip-us.apache.org/repos/asf/ignite/blob/e3dfdecc/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridLocalCacheStoreManagerDeserializationTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridLocalCacheStoreManagerDeserializationTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridLocalCacheStoreManagerDeserializationTest.java
index 827b3cf..b86fe53 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridLocalCacheStoreManagerDeserializationTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridLocalCacheStoreManagerDeserializationTest.java
@@ -86,7 +86,7 @@ public class GridLocalCacheStoreManagerDeserializationTest extends GridCacheStor
final BinaryObjectBuilder builder = grid.binary().builder("custom_type");
- final BinaryObject entity = builder.setField("id", 0).build();
+ final BinaryObject entity = builder.setField("id", 0).hashCode(0).build();
cache.put(entity, entity);
http://git-wip-us.apache.org/repos/asf/ignite/blob/e3dfdecc/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectsAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectsAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectsAbstractSelfTest.java
index 3a510c3..7936ea4 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectsAbstractSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectsAbstractSelfTest.java
@@ -28,6 +28,7 @@ import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
+import java.util.concurrent.Callable;
import javax.cache.Cache;
import javax.cache.processor.EntryProcessor;
import javax.cache.processor.EntryProcessorException;
@@ -887,6 +888,36 @@ public abstract class GridCacheBinaryObjectsAbstractSelfTest extends GridCommonA
}
/**
+ * @throws Exception If failed.
+ */
+ @SuppressWarnings({ "ThrowableResultOfMethodCallIgnored", "unchecked" })
+ public void testPutWithoutHashCode() throws Exception {
+ final IgniteCache c = jcache(0);
+
+ GridTestUtils.assertThrows(log, new Callable<Object>() {
+ /** {@inheritDoc} */
+ @Override public Object call() throws Exception {
+ c.put(new TestObject(5), 5);
+ return null;
+ }
+ }, IllegalArgumentException.class, "Cache key must override hashCode() and equals() methods: ");
+
+ BinaryObjectBuilder bldr = grid(0).binary().builder(TestObject.class.getName());
+ bldr.setField("val", 5);
+
+ final BinaryObject binKey = bldr.build();
+
+ GridTestUtils.assertThrows(log, new Callable<Object>() {
+ /** {@inheritDoc} */
+ @Override public Object call() throws Exception {
+ c.put(binKey, 5);
+ return null;
+ }
+ }, IllegalArgumentException.class, "Cache key created with BinaryBuilder is missing hash code - " +
+ "please set it explicitly during building by using BinaryBuilder.hashCode(int)");
+ }
+
+ /**
* @throws Exception if failed.
*/
public void testKeepBinaryTxOverwrite() throws Exception {
[5/8] ignite git commit: Added node stop to
IgniteCacheExpireAndUpdateConsistencyTest.
Posted by sb...@apache.org.
Added node stop to IgniteCacheExpireAndUpdateConsistencyTest.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/3e8a1c6b
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/3e8a1c6b
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/3e8a1c6b
Branch: refs/heads/ignite-3601p
Commit: 3e8a1c6b045c231dbb3c972463000f824386aee9
Parents: b280c3e
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Thu Sep 29 11:08:23 2016 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Thu Sep 29 11:08:23 2016 +0300
----------------------------------------------------------------------
.../cache/IgniteCacheExpireAndUpdateConsistencyTest.java | 7 +++++++
1 file changed, 7 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/3e8a1c6b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheExpireAndUpdateConsistencyTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheExpireAndUpdateConsistencyTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheExpireAndUpdateConsistencyTest.java
index 7f54a83..882ed22 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheExpireAndUpdateConsistencyTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheExpireAndUpdateConsistencyTest.java
@@ -97,6 +97,13 @@ public class IgniteCacheExpireAndUpdateConsistencyTest extends GridCommonAbstrac
assertTrue(client.configuration().isClientMode());
}
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ stopAllGrids();
+
+ super.afterTestsStopped();
+ }
+
/**
* @throws Exception If failed.
*/