当该字段上存在搜索索引时,Datastax DSE 5.0.x在通过Text()属性值检测现有顶点时破坏了行为

时间:2017-04-04 11:58:33

标签: datastax datastax-enterprise gremlin datastax-enterprise-graph

您好我做了这个失败的测试 - 我已将模式设置为Production并将allow_scans设置为true。我还在属性value上设置了物化索引和搜索索引:

schema.propertyKey("value").Text().create() 
schema.vertexLabel("Number").properties("value").create()
schema.vertexLabel('Number').index('byValue').materialized().by('value').add()
schema.vertexLabel('Number').index('search').search().by('va‌​lue').asString().add‌​()

我正在使用DSE 5.0.7

<dependency>
   <groupId>com.datastax.dse</groupId>
   <artifactId>dse-java-driver-graph</artifactId>
   <version>1.2.3</version>
</dependency>
public class DatastaxTransactionTest {

    private GraphTraversalSource g;

    public GraphTraversalSource getGraph() {
        DseCluster dseCluster = DseCluster.builder()
                .addContactPoint("192.168.1.24")
                .build();

        DseSession dseSession = dseCluster.connect();
        return DseGraph.traversal(dseSession, new GraphOptions().setGraphName("test"));
    }

    @Before
    public void setUp() {
        g = getGraph();
        g.V().drop().iterate();
    }

    @After
    public void clean() {
        g.V().drop().iterate();
    }

    @Test
    public void testTransactions() {
        GraphTraversalSource g = getGraph();
        g.V().drop().iterate();
        for (int i=0; i<100; i++) {
            boolean exists = g.V().has("Number", "value", "32").count().next().intValue() > 0;
            // this works: boolean exists = g.V().count().next().intValue() > 0; 
            if (!exists) {
                g.addV("Number").property("value","32").next();
                report();
            }
        }
        Assert.assertEquals(1, g.V().count().next().intValue()); //this is 100
        Assert.assertEquals(1, g.V().has("Number", "value", "32").count().next().intValue()); // this is 0!!
    }

    public void report() {
        int vCount = g.V().count().next().intValue();
        int numberCount = g.V().hasLabel("Number").count().next().intValue();
        int number32Count = g.V().has("Number", "value", "32").count().next().intValue();
        System.out.println("added Number (Total Vs: "+vCount+ ", Number Vs: "+numberCount + ", Number 32 Vs: "+number32Count );
    }
}

这只是在它不存在的情况下尝试插入一个数字顶点。纯数量的顶点上的存在工作正常,但不能通过索引工作..我的一些测试中他们传递的问题很大只是通过调试而不是运行..就好像索引没有绑定到事务但最终稍后更新..如果是这种情况则是一种非常糟糕的行为..

这是输出:

added Number (Total Vs: 1, Number Vs: 1, Number 32 Vs: 0
added Number (Total Vs: 2, Number Vs: 2, Number 32 Vs: 0
added Number (Total Vs: 3, Number Vs: 3, Number 32 Vs: 0
added Number (Total Vs: 4, Number Vs: 4, Number 32 Vs: 0
added Number (Total Vs: 5, Number Vs: 5, Number 32 Vs: 0
added Number (Total Vs: 6, Number Vs: 6, Number 32 Vs: 0
[...]
added Number (Total Vs: 97, Number Vs: 97, Number 32 Vs: 0
added Number (Total Vs: 98, Number Vs: 98, Number 32 Vs: 0
added Number (Total Vs: 99, Number Vs: 99, Number 32 Vs: 0
added Number (Total Vs: 100, Number Vs: 100, Number 32 Vs: 0


java.lang.AssertionError: 
Expected :1
Actual   :100
 <Click to see difference>


    at org.junit.Assert.fail(Assert.java:88)
    at org.junit.Assert.failNotEquals(Assert.java:834)
    at org.junit.Assert.assertEquals(Assert.java:645)
    at org.junit.Assert.assertEquals(Assert.java:631)
    at com.xxxx.DatastaxTransactionTest.testTransactions(DatastaxTransactionTest.java:53)
[...]

谢谢!

0 个答案:

没有答案