Return-Path: X-Original-To: apmail-tinkerpop-commits-archive@minotaur.apache.org Delivered-To: apmail-tinkerpop-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7D3D618DE5 for ; Thu, 3 Dec 2015 20:42:55 +0000 (UTC) Received: (qmail 38255 invoked by uid 500); 3 Dec 2015 20:42:46 -0000 Delivered-To: apmail-tinkerpop-commits-archive@tinkerpop.apache.org Received: (qmail 38230 invoked by uid 500); 3 Dec 2015 20:42:46 -0000 Mailing-List: contact commits-help@tinkerpop.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@tinkerpop.incubator.apache.org Delivered-To: mailing list commits@tinkerpop.incubator.apache.org Received: (qmail 38221 invoked by uid 99); 3 Dec 2015 20:42:46 -0000 Received: from Unknown (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Dec 2015 20:42:46 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 90D211A5D01 for ; Thu, 3 Dec 2015 20:42:45 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.227 X-Spam-Level: * X-Spam-Status: No, score=1.227 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.554, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-us-west.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id cIihayIqPZ0h for ; Thu, 3 Dec 2015 20:42:40 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with SMTP id 0A39520CF5 for ; Thu, 3 Dec 2015 20:42:40 +0000 (UTC) Received: (qmail 38148 invoked by uid 99); 3 Dec 2015 20:42:39 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Dec 2015 20:42:39 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id AC373E6827; Thu, 3 Dec 2015 20:42:39 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: spmallette@apache.org To: commits@tinkerpop.incubator.apache.org Date: Thu, 03 Dec 2015 20:42:40 -0000 Message-Id: In-Reply-To: <6c9e033c155f45559da601b2b94c703f@git.apache.org> References: <6c9e033c155f45559da601b2b94c703f@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/4] incubator-tinkerpop git commit: Loosened up assertions on types for toy graphs. Loosened up assertions on types for toy graphs. This allowed us to not have to add a supportsSchema() feature which seemed kinda excessive to add for just a single tests. There are many other tests in IO that validat types strictly so this shouldn't be a problem to loosen stuff up here a bit. Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/d59e9144 Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/d59e9144 Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/d59e9144 Branch: refs/heads/master Commit: d59e9144aa84fb274da32fbfb8d9742a3c89c43b Parents: 0e43bdd Author: Stephen Mallette Authored: Thu Dec 3 15:26:53 2015 -0500 Committer: Stephen Mallette Committed: Thu Dec 3 15:26:53 2015 -0500 ---------------------------------------------------------------------- .../tinkerpop/gremlin/structure/io/IoTest.java | 87 +++++++++++++------- 1 file changed, 57 insertions(+), 30 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d59e9144/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoTest.java ---------------------------------------------------------------------- diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoTest.java index 8f35333..40950f9 100644 --- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoTest.java +++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoTest.java @@ -50,6 +50,8 @@ import org.junit.Before; import org.junit.Test; import org.junit.experimental.runners.Enclosed; import org.junit.runner.RunWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.xml.XMLConstants; import javax.xml.transform.Source; @@ -90,6 +92,7 @@ import static org.junit.Assert.fail; */ @RunWith(Enclosed.class) public class IoTest { + private static final Logger logger = LoggerFactory.getLogger(IoTest.class); public static class GraphMLTest extends AbstractGremlinTest { @Test @@ -648,7 +651,7 @@ public class IoTest { assertEquals(6, IteratorUtils.count(g1.vertices())); assertEquals(6, IteratorUtils.count(g1.edges())); - final Vertex v1 = (Vertex) g1.traversal().V().has("name", "marko").next(); + final Vertex v1 = g1.traversal().V().has("name", "marko").next(); assertEquals(29, v1.value("age").intValue()); assertEquals(2, v1.keys().size()); assertEquals(assertSpecificLabel ? "person" : Vertex.DEFAULT_LABEL, v1.label()); @@ -660,25 +663,25 @@ public class IoTest { if (e.inVertex().value("name").equals("vadas")) { assertEquals("knows", e.label()); if (assertDouble) - assertEquals(0.5d, e.value("weight"), 0.0001d); + assertWeightLoosely(0.5d, e); else - assertEquals(0.5f, e.value("weight"), 0.0001f); + assertWeightLoosely(0.5f, e); assertEquals(1, e.keys().size()); assertId(g1, lossyForId, e, 7); } else if (e.inVertex().value("name").equals("josh")) { assertEquals("knows", e.label()); if (assertDouble) - assertEquals(1.0, e.value("weight"), 0.0001d); + assertWeightLoosely(1.0, e); else - assertEquals(1.0f, e.value("weight"), 0.0001f); + assertWeightLoosely(1.0f, e); assertEquals(1, e.keys().size()); assertId(g1, lossyForId, e, 8); } else if (e.inVertex().value("name").equals("lop")) { assertEquals("created", e.label()); if (assertDouble) - assertEquals(0.4d, e.value("weight"), 0.0001d); + assertWeightLoosely(0.4d, e); else - assertEquals(0.4f, e.value("weight"), 0.0001f); + assertWeightLoosely(0.4f, e); assertEquals(1, e.keys().size()); assertId(g1, lossyForId, e, 9); } else { @@ -686,7 +689,7 @@ public class IoTest { } }); - final Vertex v2 = (Vertex) g1.traversal().V().has("name", "vadas").next(); + final Vertex v2 = g1.traversal().V().has("name", "vadas").next(); assertEquals(27, v2.value("age").intValue()); assertEquals(2, v2.keys().size()); assertEquals(assertSpecificLabel ? "person" : Vertex.DEFAULT_LABEL, v2.label()); @@ -698,9 +701,9 @@ public class IoTest { if (e.outVertex().value("name").equals("marko")) { assertEquals("knows", e.label()); if (assertDouble) - assertEquals(0.5d, e.value("weight"), 0.0001d); + assertWeightLoosely(0.5d, e); else - assertEquals(0.5f, e.value("weight"), 0.0001f); + assertWeightLoosely(0.5f, e); assertEquals(1, e.keys().size()); assertId(g1, lossyForId, e, 7); } else { @@ -708,7 +711,7 @@ public class IoTest { } }); - final Vertex v3 = (Vertex) g1.traversal().V().has("name", "lop").next(); + final Vertex v3 = g1.traversal().V().has("name", "lop").next(); assertEquals("java", v3.value("lang")); assertEquals(2, v2.keys().size()); assertEquals(assertSpecificLabel ? "software" : Vertex.DEFAULT_LABEL, v3.label()); @@ -720,25 +723,25 @@ public class IoTest { if (e.outVertex().value("name").equals("peter")) { assertEquals("created", e.label()); if (assertDouble) - assertEquals(0.2d, e.value("weight"), 0.0001d); + assertWeightLoosely(0.2d, e); else - assertEquals(0.2f, e.value("weight"), 0.0001f); + assertWeightLoosely(0.2f, e); assertEquals(1, e.keys().size()); assertId(g1, lossyForId, e, 12); } else if (e.outVertex().value("name").equals("josh")) { assertEquals("created", e.label()); if (assertDouble) - assertEquals(0.4d, e.value("weight"), 0.0001d); + assertWeightLoosely(0.4d, e); else - assertEquals(0.4f, e.value("weight"), 0.0001f); + assertWeightLoosely(0.4f, e); assertEquals(1, e.keys().size()); assertId(g1, lossyForId, e, 11); } else if (e.outVertex().value("name").equals("marko")) { assertEquals("created", e.label()); if (assertDouble) - assertEquals(0.4d, e.value("weight"), 0.0001d); + assertWeightLoosely(0.4d, e); else - assertEquals(0.4f, e.value("weight"), 0.0001f); + assertWeightLoosely(0.4f, e); assertEquals(1, e.keys().size()); assertId(g1, lossyForId, e, 9); } else { @@ -746,7 +749,7 @@ public class IoTest { } }); - final Vertex v4 = (Vertex) g1.traversal().V().has("name", "josh").next(); + final Vertex v4 = g1.traversal().V().has("name", "josh").next(); assertEquals(32, v4.value("age").intValue()); assertEquals(2, v4.keys().size()); assertEquals(assertSpecificLabel ? "person" : Vertex.DEFAULT_LABEL, v4.label()); @@ -758,25 +761,25 @@ public class IoTest { if (e.inVertex().value("name").equals("ripple")) { assertEquals("created", e.label()); if (assertDouble) - assertEquals(1.0d, e.value("weight"), 0.0001d); + assertWeightLoosely(1.0d, e); else - assertEquals(1.0f, e.value("weight"), 0.0001f); + assertWeightLoosely(1.0f, e); assertEquals(1, e.keys().size()); assertId(g1, lossyForId, e, 10); } else if (e.inVertex().value("name").equals("lop")) { assertEquals("created", e.label()); if (assertDouble) - assertEquals(0.4d, e.value("weight"), 0.0001d); + assertWeightLoosely(0.4d, e); else - assertEquals(0.4f, e.value("weight"), 0.0001f); + assertWeightLoosely(0.4f, e); assertEquals(1, e.keys().size()); assertId(g1, lossyForId, e, 11); } else if (e.outVertex().value("name").equals("marko")) { assertEquals("knows", e.label()); if (assertDouble) - assertEquals(1.0d, e.value("weight"), 0.0001d); + assertWeightLoosely(1.0d, e); else - assertEquals(1.0f, e.value("weight"), 0.0001f); + assertWeightLoosely(1.0f, e); assertEquals(1, e.keys().size()); assertId(g1, lossyForId, e, 8); } else { @@ -784,7 +787,7 @@ public class IoTest { } }); - final Vertex v5 = (Vertex) g1.traversal().V().has("name", "ripple").next(); + final Vertex v5 = g1.traversal().V().has("name", "ripple").next(); assertEquals("java", v5.value("lang")); assertEquals(2, v5.keys().size()); assertEquals(assertSpecificLabel ? "software" : Vertex.DEFAULT_LABEL, v5.label()); @@ -796,9 +799,9 @@ public class IoTest { if (e.outVertex().value("name").equals("josh")) { assertEquals("created", e.label()); if (assertDouble) - assertEquals(1.0d, e.value("weight"), 0.0001d); + assertWeightLoosely(1.0d, e); else - assertEquals(1.0f, e.value("weight"), 0.0001f); + assertWeightLoosely(1.0f, e); assertEquals(1, e.keys().size()); assertId(g1, lossyForId, e, 10); } else { @@ -806,7 +809,7 @@ public class IoTest { } }); - final Vertex v6 = (Vertex) g1.traversal().V().has("name", "peter").next(); + final Vertex v6 = g1.traversal().V().has("name", "peter").next(); assertEquals(35, v6.value("age").intValue()); assertEquals(2, v6.keys().size()); assertEquals(assertSpecificLabel ? "person" : Vertex.DEFAULT_LABEL, v6.label()); @@ -818,9 +821,9 @@ public class IoTest { if (e.inVertex().value("name").equals("lop")) { assertEquals("created", e.label()); if (assertDouble) - assertEquals(0.2d, e.value("weight"), 0.0001d); + assertWeightLoosely(0.2d, e); else - assertEquals(0.2f, e.value("weight"), 0.0001f); + assertWeightLoosely(0.2f, e); assertEquals(1, e.keys().size()); assertId(g1, lossyForId, e, 12); } else { @@ -829,6 +832,30 @@ public class IoTest { }); } + private static void assertWeightLoosely(final double expected, final Edge e) { + try { + assertEquals(expected, e.value("weight"), 0.0001d); + } catch (Exception ex) { + // for graphs that have strong typing via schema it is possible that a value that came across as graphson + // with lossiness will end up having a value expected to double to be coerced to float by the underlying + // graph. + logger.warn("Attempting to assert weight as float for {} - if your graph is strongly typed from schema this is likely expected", e); + assertEquals(new Double(expected).floatValue(), e.value("weight"), 0.0001f); + } + } + + private static void assertWeightLoosely(final float expected, final Edge e) { + try { + assertEquals(expected, e.value("weight"), 0.0001f); + } catch (Exception ex) { + // for graphs that have strong typing via schema it is possible that a value that came across as graphson + // with lossiness will end up having a value expected to float to be coerced to double by the underlying + // graph. + logger.warn("Attempting to assert weight as double for {} - if your graph is strongly typed from schema this is likely expected", e); + assertEquals(new Float(expected).doubleValue(), e.value("weight"), 0.0001d); + } + } + private static void assertId(final Graph g, final boolean lossyForId, final Element e, final Object expected) { // it is possible that a Graph (e.g. elastic-gremlin) can supportUserSuppliedIds but internally // represent them as a value other than Numeric (which is what's in all of the test/toy data).