0

嗨,我做了这个失败的测试 - 我已将模式设置为 isProductionallow_scansto 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 );
    }
}

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

这是输出:

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)
[...]

谢谢!

4

0 回答 0