use of org.neo4j.kernel.api.properties.DefinedProperty in project neo4j by neo4j.
the class TxStateTransactionDataViewTest method shouldListAddedNodePropertiesProperties.
@Test
public void shouldListAddedNodePropertiesProperties() throws Exception {
// Given
int propertyKeyId = 1;
DefinedProperty prevProp = stringProperty(propertyKeyId, "prevValue");
state.nodeDoChangeProperty(1L, prevProp, stringProperty(propertyKeyId, "newValue"));
when(ops.propertyKeyGetName(propertyKeyId)).thenReturn("theKey");
long propertyId = 20L;
when(storeStatement.acquireSingleNodeCursor(1L)).thenReturn(asNodeCursor(1L, propertyId, labels()));
when(storeStatement.acquireSinglePropertyCursor(propertyId, propertyKeyId, NO_LOCK)).thenReturn(asPropertyCursor(prevProp));
// When
Iterable<PropertyEntry<Node>> propertyEntries = snapshot().assignedNodeProperties();
// Then
PropertyEntry<Node> entry = single(propertyEntries);
assertThat(entry.key(), equalTo("theKey"));
assertThat(entry.value(), equalTo((Object) "newValue"));
assertThat(entry.previouslyCommitedValue(), equalTo((Object) "prevValue"));
assertThat(entry.entity().getId(), equalTo(1L));
}
use of org.neo4j.kernel.api.properties.DefinedProperty in project neo4j by neo4j.
the class TxStateTransactionDataViewTest method shouldListRemovedNodeProperties.
@Test
public void shouldListRemovedNodeProperties() throws Exception {
// Given
int propertyKeyId = 1;
DefinedProperty prevProp = stringProperty(propertyKeyId, "prevValue");
state.nodeDoRemoveProperty(1L, prevProp);
when(ops.propertyKeyGetName(propertyKeyId)).thenReturn("theKey");
long propertyId = 20L;
when(storeStatement.acquireSingleNodeCursor(1L)).thenReturn(asNodeCursor(1L, propertyId, labels()));
when(storeStatement.acquireSinglePropertyCursor(propertyId, propertyKeyId, NO_LOCK)).thenReturn(asPropertyCursor(prevProp));
// When
Iterable<PropertyEntry<Node>> propertyEntries = snapshot().removedNodeProperties();
// Then
PropertyEntry<Node> entry = single(propertyEntries);
assertThat(entry.key(), equalTo("theKey"));
assertThat(entry.previouslyCommitedValue(), equalTo("prevValue"));
assertThat(entry.entity().getId(), equalTo(1L));
}
use of org.neo4j.kernel.api.properties.DefinedProperty in project neo4j by neo4j.
the class NeoStoresTest method validateRel2.
private void validateRel2(long rel, DefinedProperty prop1, DefinedProperty prop2, DefinedProperty prop3, long firstNode, long secondNode, int relType) throws IOException {
ArrayMap<Integer, Pair<DefinedProperty, Long>> props = new ArrayMap<>();
propertyLoader.relLoadProperties(rel, newPropertyReceiver(props));
int count = 0;
for (int keyId : props.keySet()) {
long id = props.get(keyId).other();
PropertyRecord record = getRecord(pStore, id);
PropertyBlock block = record.getPropertyBlock(props.get(keyId).first().propertyKeyId());
DefinedProperty data = block.newPropertyData(pStore);
if (data.propertyKeyId() == prop1.propertyKeyId()) {
assertEquals("prop1", MyPropertyKeyToken.getIndexFor(keyId).name());
assertEquals("string2", data.value());
relAddProperty(rel, prop1.propertyKeyId(), "-string2");
} else if (data.propertyKeyId() == prop2.propertyKeyId()) {
assertEquals("prop2", MyPropertyKeyToken.getIndexFor(keyId).name());
assertEquals(2, data.value());
relAddProperty(rel, prop2.propertyKeyId(), -2);
} else if (data.propertyKeyId() == prop3.propertyKeyId()) {
assertEquals("prop3", MyPropertyKeyToken.getIndexFor(keyId).name());
assertEquals(false, data.value());
relAddProperty(rel, prop3.propertyKeyId(), true);
} else {
throw new IOException();
}
count++;
}
assertEquals(3, count);
assertRelationshipData(rel, firstNode, secondNode, relType);
}
use of org.neo4j.kernel.api.properties.DefinedProperty in project neo4j by neo4j.
the class NeoStoresTest method deleteNode2.
private void deleteNode2(long node, DefinedProperty prop1, DefinedProperty prop2, DefinedProperty prop3) throws IOException {
ArrayMap<Integer, Pair<DefinedProperty, Long>> props = new ArrayMap<>();
propertyLoader.nodeLoadProperties(node, newPropertyReceiver(props));
int count = 0;
for (int keyId : props.keySet()) {
long id = props.get(keyId).other();
PropertyRecord record = pStore.getRecord(id, pStore.newRecord(), NORMAL);
PropertyBlock block = record.getPropertyBlock(props.get(keyId).first().propertyKeyId());
DefinedProperty data = block.newPropertyData(pStore);
if (data.propertyKeyId() == prop1.propertyKeyId()) {
assertEquals("prop1", MyPropertyKeyToken.getIndexFor(keyId).name());
assertEquals("-string2", data.value());
} else if (data.propertyKeyId() == prop2.propertyKeyId()) {
assertEquals("prop2", MyPropertyKeyToken.getIndexFor(keyId).name());
assertEquals(-2, data.value());
} else if (data.propertyKeyId() == prop3.propertyKeyId()) {
assertEquals("prop3", MyPropertyKeyToken.getIndexFor(keyId).name());
assertEquals(true, data.value());
transaction.nodeDoRemoveProperty(node, prop3);
} else {
throw new IOException();
}
count++;
}
assertEquals(3, count);
CountingPropertyReceiver propertyCounter = new CountingPropertyReceiver();
propertyLoader.nodeLoadProperties(node, propertyCounter);
assertEquals(3, propertyCounter.count);
assertHasRelationships(node);
transaction.nodeDoDelete(node);
}
use of org.neo4j.kernel.api.properties.DefinedProperty in project neo4j by neo4j.
the class NeoStoresTest method testCreateStore.
@Test
public void testCreateStore() throws Exception {
initializeStores(storeDir, stringMap());
startTx();
// setup test population
long node1 = nextId(Node.class);
transaction.nodeDoCreate(node1);
long node2 = nextId(Node.class);
transaction.nodeDoCreate(node2);
DefinedProperty n1prop1 = nodeAddProperty(node1, index("prop1"), "string1");
DefinedProperty n1prop2 = nodeAddProperty(node1, index("prop2"), 1);
DefinedProperty n1prop3 = nodeAddProperty(node1, index("prop3"), true);
DefinedProperty n2prop1 = nodeAddProperty(node2, index("prop1"), "string2");
DefinedProperty n2prop2 = nodeAddProperty(node2, index("prop2"), 2);
DefinedProperty n2prop3 = nodeAddProperty(node2, index("prop3"), false);
int relType1 = (int) nextId(RelationshipType.class);
String typeName1 = "relationshiptype1";
transaction.relationshipTypeDoCreateForName(typeName1, relType1);
int relType2 = (int) nextId(RelationshipType.class);
String typeName2 = "relationshiptype2";
transaction.relationshipTypeDoCreateForName(typeName2, relType2);
long rel1 = nextId(Relationship.class);
transaction.relationshipDoCreate(rel1, relType1, node1, node2);
long rel2 = nextId(Relationship.class);
transaction.relationshipDoCreate(rel2, relType2, node2, node1);
DefinedProperty r1prop1 = relAddProperty(rel1, index("prop1"), "string1");
DefinedProperty r1prop2 = relAddProperty(rel1, index("prop2"), 1);
DefinedProperty r1prop3 = relAddProperty(rel1, index("prop3"), true);
DefinedProperty r2prop1 = relAddProperty(rel2, index("prop1"), "string2");
DefinedProperty r2prop2 = relAddProperty(rel2, index("prop2"), 2);
DefinedProperty r2prop3 = relAddProperty(rel2, index("prop3"), false);
commitTx();
ds.stop();
initializeStores(storeDir, stringMap());
startTx();
// validate node
validateNodeRel1(node1, n1prop1, n1prop2, n1prop3, rel1, rel2, relType1, relType2);
validateNodeRel2(node2, n2prop1, n2prop2, n2prop3, rel1, rel2, relType1, relType2);
// validate rels
validateRel1(rel1, r1prop1, r1prop2, r1prop3, node1, node2, relType1);
validateRel2(rel2, r2prop1, r2prop2, r2prop3, node2, node1, relType2);
validateRelTypes(relType1, relType2);
// validate reltypes
validateRelTypes(relType1, relType2);
commitTx();
ds.stop();
initializeStores(storeDir, stringMap());
startTx();
// validate and delete rels
deleteRel1(rel1, r1prop1, r1prop2, r1prop3, node1, node2, relType1);
deleteRel2(rel2, r2prop1, r2prop2, r2prop3, node2, node1, relType2);
// validate and delete nodes
deleteNode1(node1, n1prop1, n1prop2, n1prop3);
deleteNode2(node2, n2prop1, n2prop2, n2prop3);
commitTx();
ds.stop();
initializeStores(storeDir, stringMap());
startTx();
assertFalse(nodeExists(node1));
assertFalse(nodeExists(node2));
testGetRels(new long[] { rel1, rel2 });
long[] nodeIds = new long[10];
for (int i = 0; i < 3; i++) {
nodeIds[i] = nextId(Node.class);
transaction.nodeDoCreate(nodeIds[i]);
nodeAddProperty(nodeIds[i], index("nisse"), 10 - i);
}
for (int i = 0; i < 2; i++) {
long id = nextId(Relationship.class);
transaction.relationshipDoCreate(id, relType1, nodeIds[i], nodeIds[i + 1]);
transaction.relationshipDoDelete(id, relType1, nodeIds[i], nodeIds[i + 1]);
}
for (int i = 0; i < 3; i++) {
transaction.nodeDoDelete(nodeIds[i]);
}
commitTx();
ds.stop();
}
Aggregations