org.umlg.sqlg.test.batch.TestBatchJson Maven / Gradle / Ivy
package org.umlg.sqlg.test.batch;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;
import org.umlg.sqlg.structure.BatchManager;
import org.umlg.sqlg.test.BaseTest;
import java.util.List;
import static org.junit.Assert.assertEquals;
/**
* Date: 2016/05/09
* Time: 9:20 PM
*/
public class TestBatchJson extends BaseTest {
@Before
public void beforeTest() {
Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportsBatchMode());
}
@Test
public void testJson() {
ObjectMapper objectMapper = new ObjectMapper();
ObjectNode json = new ObjectNode(objectMapper.getNodeFactory());
json.put("username", "john");
this.sqlgGraph.tx().batchMode(BatchManager.BatchModeType.NORMAL);
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "doc", json);
this.sqlgGraph.tx().commit();
assertEquals(json, this.sqlgGraph.traversal().V(a1).values("doc").next());
}
@Test
public void batchJson() {
ObjectMapper objectMapper = new ObjectMapper();
ObjectNode json = new ObjectNode(objectMapper.getNodeFactory());
json.put("username", "john");
this.sqlgGraph.tx().normalBatchModeOn();
for (int i = 0; i < 10; i++) {
this.sqlgGraph.addVertex(T.label, "Person", "doc", json);
}
this.sqlgGraph.tx().commit();
List vertices = this.sqlgGraph.traversal().V().hasLabel("Person").toList();
assertEquals(10, vertices.size());
JsonNode value = vertices.get(0).value("doc");
assertEquals(json, value);
}
@Test
public void batchUpdateJson() {
ObjectMapper objectMapper = new ObjectMapper();
ObjectNode json = new ObjectNode(objectMapper.getNodeFactory());
json.put("username", "john");
this.sqlgGraph.tx().normalBatchModeOn();
for (int i = 0; i < 10; i++) {
this.sqlgGraph.addVertex(T.label, "Person", "doc", json);
}
this.sqlgGraph.tx().commit();
List vertices = this.sqlgGraph.traversal().V().hasLabel("Person").toList();
assertEquals(10, vertices.size());
JsonNode value = vertices.get(0).value("doc");
assertEquals(json, value);
this.sqlgGraph.tx().normalBatchModeOn();
json = new ObjectNode(objectMapper.getNodeFactory());
json.put("username", "pete");
for (Vertex vertex : vertices) {
vertex.property("doc", json);
}
this.sqlgGraph.tx().commit();
vertices = this.sqlgGraph.traversal().V().hasLabel("Person").toList();
assertEquals(10, vertices.size());
value = vertices.get(0).value("doc");
assertEquals(json, value);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy