@Test
  public void shouldBeAbleToGetPropertiesOnRelationship() throws Exception {

    long relationshipId;
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put("foo", "bar");
    properties.put("neo", "Thomas A. Anderson");
    properties.put("number", 15L);
    Transaction tx = database.getGraph().beginTx();
    try {
      Node startNode = database.getGraph().createNode();
      Node endNode = database.getGraph().createNode();
      Relationship relationship =
          startNode.createRelationshipTo(endNode, DynamicRelationshipType.withName("knows"));
      for (Map.Entry<String, Object> entry : properties.entrySet()) {
        relationship.setProperty(entry.getKey(), entry.getValue());
      }
      relationshipId = relationship.getId();
      tx.success();
    } finally {
      tx.finish();
    }

    Map<String, Object> readProperties =
        serialize(actions.getAllRelationshipProperties(relationshipId));
    assertEquals(properties, readProperties);
  }
  @Test
  public void shouldOverwriteExistingProperties()
      throws PropertyValueException, NodeNotFoundException {

    long nodeId;
    Transaction tx = database.getGraph().beginTx();
    try {
      Node node = database.getGraph().createNode();
      node.setProperty("remove me", "trash");
      nodeId = node.getId();
      tx.success();
    } finally {
      tx.finish();
    }
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put("foo", "bar");
    properties.put("baz", 17);
    actions.setAllNodeProperties(nodeId, properties);
    tx = database.getGraph().beginTx();
    try {
      Node node = database.getGraph().getNodeById(nodeId);
      assertHasProperties(node, properties);
      assertNull(node.getProperty("remove me", null));
    } finally {
      tx.finish();
    }
  }
 private void addPropertyToReferenceNode() {
   Transaction tx = db.getGraph().beginTx();
   Node n = db.getGraph().getReferenceNode();
   n.setProperty("monkey", "rock!");
   tx.success();
   tx.finish();
 }
Example #4
0
  public org.neo4j.server.database.RrdDbWrapper createRrdDbAndSampler(
      final Database db, JobScheduler scheduler) throws IOException {
    NodeManager nodeManager =
        db.getGraph().getDependencyResolver().resolveDependency(NodeManager.class);

    Sampleable[] primitives = {
      new NodeIdsInUseSampleable(nodeManager),
      new PropertyCountSampleable(nodeManager),
      new RelationshipCountSampleable(nodeManager)
    };

    Sampleable[] usage = {};

    final String rrdPath =
        config.getString(RRDB_LOCATION_PROPERTY_KEY, getDefaultRrdFile(db.getGraph()));
    final RrdDbWrapper rrdb =
        createRrdb(rrdPath, isEphemereal(db.getGraph()), join(primitives, usage));

    scheduler.scheduleAtFixedRate(
        new RrdJob(new RrdSamplerImpl(rrdb.get(), primitives)),
        RRD_THREAD_NAME + "[primitives]",
        SECONDS.toMillis(0),
        SECONDS.toMillis(3));

    return rrdb;
  }
  @Test
  public void createdNodeShouldBeInDatabase() throws Exception {
    NodeRepresentation noderep = actions.createNode(Collections.<String, Object>emptyMap());

    Transaction tx = database.getGraph().beginTx();
    try {
      assertNotNull(database.getGraph().getNodeById(noderep.getId()));
    } finally {
      tx.finish();
    }
  }
  private long createNode(Map<String, Object> properties) {

    long nodeId;
    Transaction tx = database.getGraph().beginTx();
    try {
      Node node = database.getGraph().createNode();
      for (Map.Entry<String, Object> entry : properties.entrySet()) {
        node.setProperty(entry.getKey(), entry.getValue());
      }
      nodeId = node.getId();
      tx.success();
    } finally {
      tx.finish();
    }
    return nodeId;
  }
  @Test
  public void shouldRemoveNodeWithNoRelationsFromDBOnDelete()
      throws NodeNotFoundException, OperationFailureException {
    long nodeId;
    Transaction tx = database.getGraph().beginTx();
    try {
      Node node = database.getGraph().createNode();
      nodeId = node.getId();
      tx.success();
    } finally {
      tx.finish();
    }

    int nodeCount = graphdbHelper.getNumberOfNodes();
    actions.deleteNode(nodeId);
    assertEquals(nodeCount - 1, graphdbHelper.getNumberOfNodes());
  }
  @Test
  public void shouldBeAbleToRemoveNodeProperties() throws Exception {
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put("foo", "bar");
    properties.put("number", 15);
    long nodeId = createNode(properties);
    actions.removeAllNodeProperties(nodeId);

    Transaction tx = database.getGraph().beginTx();
    try {
      Node node = database.getGraph().getNodeById(nodeId);
      assertEquals(false, node.getPropertyKeys().iterator().hasNext());
      tx.success();
    } finally {
      tx.finish();
    }
  }
  @Test
  public void shouldBeAbleToStorePropertiesInAnExistingNode()
      throws PropertyValueException, NodeNotFoundException {
    long nodeId = graphdbHelper.createNode();
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put("foo", "bar");
    properties.put("baz", 17);
    actions.setAllNodeProperties(nodeId, properties);

    Transaction tx = database.getGraph().beginTx();
    try {
      Node node = database.getGraph().getNodeById(nodeId);
      assertHasProperties(node, properties);
    } finally {
      tx.finish();
    }
  }
  private void addNodeIntoGraph() {
    Transaction tx = db.getGraph().beginTx();
    Node referenceNode = db.getGraph().getReferenceNode();
    Node myNewNode = db.getGraph().createNode();
    myNewNode.setProperty("id", UUID.randomUUID().toString());
    myNewNode.createRelationshipTo(
        referenceNode,
        new RelationshipType() {
          @Override
          public String name() {
            return "knows_about";
          }
        });

    tx.success();
    tx.finish();
  }
 @Before
 public void startDatabase() throws IOException {
   graph = (InternalAbstractGraphDatabase) new TestGraphDatabaseFactory().newImpermanentDatabase();
   database = new WrappedDatabase(graph);
   helper = new GraphDbHelper(database);
   output = new EntityOutputFormat(new JsonFormat(), URI.create(BASE_URI), null);
   leaseManager = new LeaseManager(new FakeClock());
   service =
       new RestfulGraphDatabase(
           new JsonFormat(), output, new DatabaseActions(leaseManager, true, database.getGraph()));
   service = new TransactionWrappingRestfulGraphDatabase(graph, service);
 }
  private long createListOfNodes(int numberOfNodes) {
    Transaction tx = database.getGraph().beginTx();
    try {
      long zerothNode = helper.createNode(MapUtil.map("name", String.valueOf(0)));
      long previousNodeId = zerothNode;
      for (int i = 1; i < numberOfNodes; i++) {
        long currentNodeId = helper.createNode(MapUtil.map("name", String.valueOf(i)));
        database
            .getGraph()
            .getNodeById(previousNodeId)
            .createRelationshipTo(
                database.getGraph().getNodeById(currentNodeId),
                DynamicRelationshipType.withName("PRECEDES"));
        previousNodeId = currentNodeId;
      }

      tx.success();
      return zerothNode;
    } finally {
      tx.finish();
    }
  }
  @Test
  public void shouldBeAbleToGetPropertiesOnNode() throws NodeNotFoundException {

    long nodeId;
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put("foo", "bar");
    properties.put("neo", "Thomas A. Anderson");
    properties.put("number", 15L);
    Transaction tx = database.getGraph().beginTx();
    try {
      Node node = database.getGraph().createNode();
      for (Map.Entry<String, Object> entry : properties.entrySet()) {
        node.setProperty(entry.getKey(), entry.getValue());
      }
      nodeId = node.getId();
      tx.success();
    } finally {
      tx.finish();
    }

    Map<String, Object> readProperties = serialize(actions.getAllNodeProperties(nodeId));
    assertEquals(properties, readProperties);
  }
  @Test
  public void shouldStoreSuppliedPropertiesWhenCreatingRelationship() throws Exception {
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put("string", "value");
    properties.put("integer", 17);
    long relId =
        actions
            .createRelationship(
                graphdbHelper.createNode(), graphdbHelper.createNode(), "LOVES", properties)
            .getId();

    Transaction tx = database.getGraph().beginTx();
    try {
      Relationship rel = database.getGraph().getRelationshipById(relId);
      for (String key : rel.getPropertyKeys()) {
        assertTrue("extra property stored", properties.containsKey(key));
      }
      for (Map.Entry<String, Object> entry : properties.entrySet()) {
        assertEquals(entry.getValue(), rel.getProperty(entry.getKey()));
      }
    } finally {
      tx.finish();
    }
  }
 @Before
 public void setUp() throws Exception {
   db = new WrappingDatabase(new ImpermanentGraphDatabase());
   sampleable = new PropertyCountSampleable(db.getGraph());
 }
 @After
 public void shutdownDatabase() throws Throwable {
   db.getGraph().shutdown();
 }
Example #17
0
 @After
 public void tearDown() {
   db.getGraph().shutdown();
 }