Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
jexp committed Feb 4, 2013
2 parents 768eb0f + 1e01b28 commit 56b7d30
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 38 deletions.
19 changes: 19 additions & 0 deletions src/main/java/org/neo4j/kernel/impl/transaction/Neo4j18Locker.java
@@ -1,3 +1,22 @@
/**
* Copyright (c) 2002-2013 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.kernel.impl.transaction; package org.neo4j.kernel.impl.transaction;


import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.GraphDatabaseService;
Expand Down
Expand Up @@ -38,12 +38,6 @@
*/ */
package org.neo4j.collections.indexprovider; package org.neo4j.collections.indexprovider;


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import java.util.HashMap;
import java.util.Map;

import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.neo4j.collections.timeline.Timeline; import org.neo4j.collections.timeline.Timeline;
Expand All @@ -58,70 +52,72 @@
import org.neo4j.visualization.graphviz.GraphvizWriter; import org.neo4j.visualization.graphviz.GraphvizWriter;
import org.neo4j.walk.Walker; import org.neo4j.walk.Walker;


public class TimelineIndexProviderTest import java.util.HashMap;
{ import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

public class TimelineIndexProviderTest {


private ImpermanentGraphDatabase db; private ImpermanentGraphDatabase db;


@Before @Before
public void setup() throws Exception public void setup() throws Exception {
{
db = new ImpermanentGraphDatabase(); db = new ImpermanentGraphDatabase();
db.cleanContent( true ); db.cleanContent(true);
} }


@Test @Test
public void testLoadIndex() public void testLoadIndex() {
{
Map<String, String> config = TimelineIndexProvider.CONFIG; Map<String, String> config = TimelineIndexProvider.CONFIG;
IndexManager indexMan = db.index(); IndexManager indexMan = db.index();
Index<Node> index = indexMan.forNodes( "timeline1", config ); Index<Node> index = indexMan.forNodes("timeline1", config);
assertNotNull( index ); assertNotNull(index);


} }

@Test @Test
public void testLoadIndexWithRootNode() public void testLoadIndexWithRootNode() {
{ Map<String, String> config = new HashMap<String, String>(TimelineIndexProvider.CONFIG);
Map<String, String> config = new HashMap<String, String> (TimelineIndexProvider.CONFIG);
final Node startNode = db.getReferenceNode(); final Node startNode = db.getReferenceNode();
config.put(TimelineNodeIndex.START_NODE_ID,String.valueOf(startNode.getId())); config.put(TimelineNodeIndex.START_NODE_ID, String.valueOf(startNode.getId()));
IndexManager indexMan = db.index(); IndexManager indexMan = db.index();
Index<Node> index = indexMan.forNodes( "timeline1", config ); Index<Node> index = indexMan.forNodes("timeline1", config);
final Timeline timeline = ((TimelineNodeIndex) index).getTimeline(); final Timeline timeline = ((TimelineNodeIndex) index).getTimeline();
assertEquals(startNode, timeline.getUnderlyingNode()); assertEquals(startNode, timeline.getUnderlyingNode());
assertNotNull( index ); assertNotNull(index);


} }


@Test @Test
public void testAddToIndex() throws Exception public void testAddToIndex() throws Exception {
{
Map<String, String> config = TimelineIndexProvider.CONFIG; Map<String, String> config = TimelineIndexProvider.CONFIG;
IndexManager indexMan = db.index(); IndexManager indexMan = db.index();
Index<Node> index = indexMan.forNodes( "timeline1", config ); Index<Node> index = indexMan.forNodes("timeline1", config);
assertNotNull( index ); assertNotNull(index);
Transaction tx = db.beginTx(); Transaction tx = db.beginTx();
Node n1 = db.createNode(); Node n1 = db.createNode();
n1.setProperty( "time", 123 ); n1.setProperty("time", 123);
index.add( n1, "timestamp", 123L ); index.add(n1, "timestamp", 123L);
Node n2 = db.createNode(); Node n2 = db.createNode();
n2.setProperty( "time", 123 ); n2.setProperty("time", 123);
index.add( n2, "timestamp", 123L ); index.add(n2, "timestamp", 123L);
Node n3 = db.createNode(); Node n3 = db.createNode();
n3.setProperty( "time", 124 ); n3.setProperty("time", 124);
index.add( n3, "timestamp", 124L ); index.add(n3, "timestamp", 124L);
tx.success(); tx.success();
tx.finish(); tx.finish();
GraphvizWriter writer = new GraphvizWriter(); GraphvizWriter writer = new GraphvizWriter();
writer.emit( System.out, Walker.fullGraph( db )); writer.emit(System.out, Walker.fullGraph(db));
IndexHits<Node> hits = index.get( "timestamp", 123L ); IndexHits<Node> hits = index.get("timestamp", 123L);
assertEquals(2, hits.size()); assertEquals(2, hits.size());
hits = index.query( "[122 TO 125]" ); hits = index.query("[122 TO 125]");
assertEquals(3, hits.size()); assertEquals(3, hits.size());

ExecutionEngine engine = new ExecutionEngine( db ); ExecutionEngine engine = new ExecutionEngine(db);
ExecutionResult result = engine.execute( "start n=node:timeline1('[100 TO 200]') return n" ); ExecutionResult result = engine.execute("start n=node:timeline1('[100 TO 200]') return n");
System.out.println( result.toString() ); System.out.println(result.toString());


} }


Expand Down

0 comments on commit 56b7d30

Please sign in to comment.