Skip to content

Commit

Permalink
Merge branch 'master' into 4bplus
Browse files Browse the repository at this point in the history
Conflicts:
	kernel/src/main/java/org/neo4j/kernel/Config.java
	kernel/src/test/java/org/neo4j/kernel/impl/nioneo/store/TestXa.java
  • Loading branch information
tinwelint committed Mar 3, 2011
2 parents 9641404 + 2363559 commit d16080b
Show file tree
Hide file tree
Showing 50 changed files with 1,234 additions and 204 deletions.
8 changes: 8 additions & 0 deletions com/src/main/java/org/neo4j/com/MasterUtil.java
Expand Up @@ -74,11 +74,19 @@ private static String relativePath( File baseDir, File storeFile ) throws FileNo

public static SlaveContext rotateLogsAndStreamStoreFiles( GraphDatabaseService graphDb, StoreWriter writer )
{
if ( Config.osIsWindows() )
{
throw new UnsupportedOperationException(
"Streaming store files live (as used in HA and backup) "
+ "isn't supported on Windows due to limitations in OS/filesystem" );
}

File baseDir = getBaseDir( graphDb );
XaDataSourceManager dsManager =
((AbstractGraphDatabase) graphDb).getConfig().getTxModule().getXaDataSourceManager();
Collection<XaDataSource> sources = dsManager.getAllRegisteredDataSources();

@SuppressWarnings( "unchecked" )
Pair<String, Long>[] appliedTransactions = new Pair[sources.size()];
int i = 0;
for ( XaDataSource ds : sources )
Expand Down
Expand Up @@ -32,9 +32,11 @@
@Service.Implementation( KernelExtension.class )
public class OnlineBackupExtension extends KernelExtension<BackupServer>
{
static final String KEY = "online backup";

public OnlineBackupExtension()
{
super( "online backup" );
super( KEY );
}

@Override
Expand Down
11 changes: 7 additions & 4 deletions com/src/test/java/org/neo4j/com/backup/TestBackup.java
Expand Up @@ -40,12 +40,14 @@
public class TestBackup
{
private String serverPath = "target/var/serverdb";
private String otherServerPath = serverPath + "2";
private String backupPath = "target/var/backuedup-serverdb";

@Before
public void before() throws Exception
{
FileUtils.deleteDirectory( new File( serverPath ) );
FileUtils.deleteDirectory( new File( otherServerPath ) );
FileUtils.deleteDirectory( new File( backupPath ) );
}

Expand Down Expand Up @@ -89,6 +91,7 @@ public void makeSureIncrementalFailsWhenNoDb() throws Exception
@Test
public void fullThenIncremental() throws Exception
{
if ( Config.osIsWindows() ) return;
DbRepresentation initialDataSetRepresentation = createInitialDataSet( serverPath );
ServerInterface server = startServer( serverPath );
OnlineBackup backup = OnlineBackup.from( "localhost" );
Expand All @@ -106,6 +109,7 @@ public void fullThenIncremental() throws Exception
@Test
public void makeSureStoreIdIsEnforced() throws Exception
{
if ( Config.osIsWindows() ) return;
// Create data set X on server A
DbRepresentation initialDataSetRepresentation = createInitialDataSet( serverPath );
ServerInterface server = startServer( serverPath );
Expand All @@ -117,10 +121,9 @@ public void makeSureStoreIdIsEnforced() throws Exception
shutdownServer( server );

// Create data set X+Y on server B
String serverPath2 = serverPath + "2";
createInitialDataSet( serverPath2 );
addMoreData( serverPath2 );
server = startServer( serverPath2 );
createInitialDataSet( otherServerPath );
addMoreData( otherServerPath );
server = startServer( otherServerPath );

// Try to grab incremental backup from server B.
// Data should be OK, but store id check should prevent that.
Expand Down
Expand Up @@ -29,21 +29,24 @@
import org.junit.Before;
import org.junit.Test;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.kernel.Config;
import org.neo4j.kernel.EmbeddedGraphDatabase;

public class TestConfiguration
{
private static final String SOURCE_DIR = "target/db";
private static final String BACKUP_DIR = "target/full-backup";

@Before
public void before() throws Exception
{
FileUtils.deleteDirectory( new File( SOURCE_DIR ) );
FileUtils.deleteDirectory( new File( BACKUP_DIR ) );
}

private GraphDatabaseService newDb( String onlineBackupConfig )
{
String path = "target/db";
String path = SOURCE_DIR;
return onlineBackupConfig == null ?
new EmbeddedGraphDatabase( path ) :
new EmbeddedGraphDatabase( path, stringMap( ENABLE_ONLINE_BACKUP, onlineBackupConfig ) );
Expand Down Expand Up @@ -82,6 +85,7 @@ public void testOffByConfig() throws Exception
@Test
public void testEnableDefaultsInConfig() throws Exception
{
if ( Config.osIsWindows() ) return;
GraphDatabaseService db = newDb( "true" );
OnlineBackup.from( "localhost" ).full( BACKUP_DIR );
db.shutdown();
Expand All @@ -90,6 +94,7 @@ public void testEnableDefaultsInConfig() throws Exception
@Test
public void testEnableCustomPortInConfig() throws Exception
{
if ( Config.osIsWindows() ) return;
int customPort = 12345;
GraphDatabaseService db = newDb( "port=" + customPort );
try
Expand Down
@@ -0,0 +1,44 @@
/**
* Copyright (c) 2002-2011 "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 Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.com.backup;

import java.util.Map;

import org.neo4j.kernel.Config;
import org.neo4j.kernel.KernelExtensionContractTest;

public class TestOnlineBackupExtension extends KernelExtensionContractTest<BackupServer, OnlineBackupExtension>
{
public TestOnlineBackupExtension()
{
super( OnlineBackupExtension.KEY, OnlineBackupExtension.class );
}

@Override
protected Map<String, String> configuration( boolean shouldLoad, int instance )
{
Map<String, String> configuration = super.configuration( shouldLoad, instance );
if ( shouldLoad )
{
configuration.put( Config.ENABLE_ONLINE_BACKUP, "port=" + ( BackupServer.DEFAULT_PORT + instance ) );
}
return configuration;
}
}
Expand Up @@ -20,6 +20,7 @@
package org.neo4j.graphalgo;

import org.neo4j.graphalgo.impl.util.DoubleEvaluator;
import org.neo4j.graphalgo.impl.util.DoubleEvaluatorWithDefault;
import org.neo4j.graphalgo.impl.util.GeoEstimateEvaluator;
import org.neo4j.graphalgo.impl.util.IntegerEvaluator;

Expand All @@ -36,6 +37,11 @@ public static CostEvaluator<Double> doubleCostEvaluator( String relationshipCost
return new DoubleEvaluator( relationshipCostPropertyKey );
}

public static CostEvaluator<Double> doubleCostEvaluator( String relationshipCostPropertyKey, double defaultCost )
{
return new DoubleEvaluatorWithDefault( relationshipCostPropertyKey, defaultCost );
}

public static CostEvaluator<Integer> intCostEvaluator( String relationshipCostPropertyKey )
{
return new IntegerEvaluator( relationshipCostPropertyKey );
Expand Down
@@ -0,0 +1,42 @@
/**
* Copyright (c) 2002-2011 "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 Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.graphalgo.impl.util;

import org.neo4j.graphalgo.CostEvaluator;
import org.neo4j.graphdb.Direction;
import org.neo4j.graphdb.Relationship;

public class DoubleEvaluatorWithDefault implements CostEvaluator<Double>
{
private String costPropertyName;
private final double defaultCost;

public DoubleEvaluatorWithDefault( String costPropertyName, double defaultCost )
{
super();
this.costPropertyName = costPropertyName;
this.defaultCost = defaultCost;
}

public Double getCost( Relationship relationship, Direction direction )
{
return (Double) relationship.getProperty( costPropertyName, defaultCost );
}
}
25 changes: 24 additions & 1 deletion graph-algo/src/test/java/common/Neo4jAlgoTestCase.java
Expand Up @@ -23,6 +23,7 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
Expand Down Expand Up @@ -59,7 +60,9 @@ protected static enum MyRelTypes implements RelationshipType
@BeforeClass
public static void setUpGraphDb() throws Exception
{
graphDb = new EmbeddedGraphDatabase( "target/var/algotest" );
String storeDir = "target/var/algotest";
deleteFileOrDirectory( new File( storeDir ) );
graphDb = new EmbeddedGraphDatabase( storeDir );
graph = new SimpleGraphBuilder( graphDb, MyRelTypes.R1 );
}

Expand Down Expand Up @@ -90,6 +93,26 @@ protected void restartTx()
tx = graphDb.beginTx();
}

public static void deleteFileOrDirectory( File file )
{
if ( !file.exists() )
{
return;
}

if ( file.isDirectory() )
{
for ( File child : file.listFiles() )
{
deleteFileOrDirectory( child );
}
}
else
{
file.delete();
}
}

protected void assertPathDef( Path path, String... names )
{
int i = 0;
Expand Down
Expand Up @@ -20,6 +20,9 @@
package org.neo4j.graphalgo.path;

import static org.junit.Assert.fail;
import static org.neo4j.helpers.collection.MapUtil.map;

import java.util.Map;

import org.junit.Test;
import org.neo4j.graphalgo.CommonEvaluators;
Expand All @@ -35,8 +38,7 @@

public class TestDijkstra extends Neo4jAlgoTestCase
{
@Test
public void testSmallGraph()
private Relationship createGraph( boolean includeOnes )
{
/* Layout:
* (y)
Expand All @@ -49,19 +51,29 @@ public void testSmallGraph()
* v / | / \ /
* (b)--[1]-->(c)--[1]->(d)
*/

Map<String, Object> propertiesForOnes = includeOnes ? map( "cost", (double) 1 ) : map();

graph.makeEdge( "start", "a", "cost", (double) 1 );
graph.makeEdge( "a", "x", "cost", (double) 9 );
graph.makeEdge( "a", "b", "cost", (double) 1 );
graph.makeEdge( "a", "b", propertiesForOnes );
graph.makeEdge( "b", "x", "cost", (double) 7 );
graph.makeEdge( "b", "c", "cost", (double) 1 );
graph.makeEdge( "b", "c", propertiesForOnes );
graph.makeEdge( "c", "x", "cost", (double) 5 );
Relationship shortCTOXRelationship = graph.makeEdge( "c", "x", "cost", (double) 3 );
graph.makeEdge( "c", "d", "cost", (double) 1 );
graph.makeEdge( "c", "d", propertiesForOnes );
graph.makeEdge( "d", "x", "cost", (double) 3 );
graph.makeEdge( "d", "e", "cost", (double) 1 );
graph.makeEdge( "e", "x", "cost", (double) 1 );
graph.makeEdge( "d", "e", propertiesForOnes );
graph.makeEdge( "e", "x", propertiesForOnes );
graph.makeEdge( "e", "f", "cost", (double) 2 );
graph.makeEdge( "x", "y", "cost", (double) 2 );
return shortCTOXRelationship;
}

@Test
public void testSmallGraph()
{
Relationship shortCTOXRelationship = createGraph( true );

PathFinder<WeightedPath> finder = GraphAlgoFactory.dijkstra(
Traversal.expanderForTypes( MyRelTypes.R1, Direction.OUTGOING ), "cost" );
Expand All @@ -88,6 +100,32 @@ public void testSmallGraph()
}
}

@Test
public void testSmallGraphWithDefaults()
{
Relationship shortCTOXRelationship = createGraph( true );

PathFinder<WeightedPath> finder = GraphAlgoFactory.dijkstra(
Traversal.expanderForTypes( MyRelTypes.R1, Direction.OUTGOING ),
CommonEvaluators.doubleCostEvaluator( "cost", 1.0d ) );

// Assert that there are two matching paths
Node startNode = graph.getNode( "start" );
Node endNode = graph.getNode( "x" );
assertPaths( finder.findAllPaths( startNode, endNode ),
"start,a,b,c,x", "start,a,b,c,d,e,x" );

// Assert that for the shorter one it picked the correct relationship
// of the two from (c) --> (x)
for ( WeightedPath path : finder.findAllPaths( startNode, endNode ) )
{
if ( getPathDef( path ).equals( "start,a,b,c,x" ) )
{
assertContainsRelationship( path, shortCTOXRelationship );
}
}
}

private void assertContainsRelationship( WeightedPath path,
Relationship relationship )
{
Expand Down
6 changes: 5 additions & 1 deletion ha/src/test/java/org/neo4j/ha/LocalhostZooKeeperCluster.java
Expand Up @@ -136,7 +136,11 @@ private String config( TargetDirectory target, int id, int port )
conf.println( "tickTime=2000" );
conf.println( "initLimit=10" );
conf.println( "syncLimit=5" );
conf.println( "dataDir=" + dataDir.getAbsolutePath() );

// On Windows the backslashes will have to be escaped for
// ZooKeeper to interpret them correctly.
conf.println( "dataDir=" + dataDir.getAbsolutePath().replaceAll( "\\\\", "\\\\\\\\" ) );

conf.println( "clientPort=" + port );
for ( int j = 0; j < keeper.length; j++ )
{
Expand Down

0 comments on commit d16080b

Please sign in to comment.