DATAGRAPH-355 Upgrade to Neo4j 1.9.GA

This commit is contained in:
Michael Hunger
2013-05-28 03:06:52 +02:00
parent f3452ba2e0
commit dbea0e81ed
21 changed files with 152 additions and 238 deletions

View File

@@ -34,14 +34,14 @@
<dist.id>spring-data-neo4j</dist.id>
<springdata.commons>1.6.0.BUILD-SNAPSHOT</springdata.commons>
<neo4j.version>1.8.1</neo4j.version>
<neo4j.version>1.9</neo4j.version>
<neo4j.spatial.version>0.10.1</neo4j.spatial.version>
<neo4j.graph-collections.version>0.5</neo4j.graph-collections.version>
<neo4j.spatial.version>0.11-neo4j-1.9</neo4j.spatial.version>
<neo4j.graph-collections.version>0.6-neo4j-1.9</neo4j.graph-collections.version>
<blueprints.version>1.2</blueprints.version>
<gremlin.version>1.5</gremlin.version>
<pipes.version>1.5</pipes.version>
<neo4j-cypher-dsl.version>1.9.M04</neo4j-cypher-dsl.version>
<neo4j-cypher-dsl.version>1.9</neo4j-cypher-dsl.version>
</properties>

View File

@@ -126,7 +126,7 @@
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2</version>
<version>2.2.2</version>
</dependency>
<dependency>
@@ -162,6 +162,10 @@
<artifactId>blueprints-neo4j-graph</artifactId>
<version>${blueprints.version}</version>
<exclusions>
<exclusion>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-management</artifactId>
</exclusion>
<exclusion>
<groupId>org.neo4j</groupId>
<artifactId>neo4j</artifactId>

View File

@@ -102,7 +102,7 @@ public class GraphRepositoryTests extends EntityTestBase {
Page<Person> teamMemberPage1 = personRepository.findAllTeamMembersPaged(testTeam.sdg,null);
assertEquals(new HashSet(asList(testTeam.david, testTeam.emil, testTeam.michael)), addToCollection(teamMemberPage1, new HashSet()));
assertThat(teamMemberPage1.isFirstPage(), is(true));
assertThat(teamMemberPage1.isLastPage(), is(false));
assertThat(teamMemberPage1.isLastPage(), is(true));
}
@Test

View File

@@ -82,7 +82,7 @@
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2</version>
<version>2.2.2</version>
</dependency>
<!-- JPA -->

View File

@@ -46,7 +46,7 @@ public class DataGraphNamespaceHandlerCrossStoreTests {
Assert.assertNotNull("template", template);
EmbeddedGraphDatabase graphDatabaseService = (EmbeddedGraphDatabase) template.getGraphDatabaseService();
File directory = new File("target", "config-test");
Assert.assertTrue("store-dir", graphDatabaseService.getStoreDir().equals(directory.getAbsolutePath()));
Assert.assertTrue("store-dir", graphDatabaseService.getStoreDir().equals(directory.getPath()));
Assert.assertNotNull("graphDatabaseService", graphDatabaseService);
Assert.assertNotNull("transactionManager", transactionManager);
}

View File

@@ -86,7 +86,7 @@
<profile>
<id>1.8.M07</id>
<properties>
<neo4j.version>1.8.M06</neo4j.version>
<neo4j.version>1.8.M07</neo4j.version>
</properties>
</profile>
</profiles>

View File

@@ -229,7 +229,7 @@
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>2.2</version>
<version>2.2.2</version>
</dependency>
<dependency>

View File

@@ -229,7 +229,7 @@
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>2.2</version>
<version>2.2.2</version>
</dependency>
<!-- Neo4j Libraries -->

View File

@@ -19,7 +19,7 @@
<properties>
<validation>1.0.0.GA</validation>
<jersey.version>1.4</jersey.version>
<neo4j-rest-graphdb.version>1.8.1</neo4j-rest-graphdb.version>
<neo4j-rest-graphdb.version>1.9</neo4j-rest-graphdb.version>
</properties>
<dependencies>
@@ -197,6 +197,10 @@
<version>${blueprints.version}</version>
<optional>true</optional>
<exclusions>
<exclusion>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-management</artifactId>
</exclusion>
<exclusion>
<groupId>org.neo4j</groupId>
<artifactId>neo4j</artifactId>

View File

@@ -1,199 +0,0 @@
/**
* Copyright 2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.neo4j.rest.support;
import org.mortbay.component.LifeCycle;
import org.mortbay.jetty.Server;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.server.CommunityNeoServer;
import org.neo4j.server.configuration.PropertyFileConfigurator;
import org.neo4j.server.database.Database;
import org.neo4j.server.database.WrappingDatabase;
import org.neo4j.server.modules.RESTApiModule;
import org.neo4j.server.modules.ServerModule;
import org.neo4j.server.modules.ThirdPartyJAXRSModule;
import org.neo4j.server.startup.healthcheck.StartupHealthCheck;
import org.neo4j.server.web.Jetty6WebServer;
import org.neo4j.server.web.WebServer;
import org.neo4j.test.ImpermanentGraphDatabase;
import java.io.File;
import java.net.URI;
import java.net.URL;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import static java.util.Arrays.asList;
public class LocalTestServer {
private CommunityNeoServer neoServer;
private final int port;
private final String hostname;
protected String propertiesFile = "test-db.properties";
private final ImpermanentGraphDatabase graphDatabase;
public LocalTestServer() {
this("localhost",7473);
}
public LocalTestServer(String hostname, int port) {
this.port = port;
this.hostname = hostname;
graphDatabase = new ImpermanentGraphDatabase();
}
public void start() {
if (neoServer!=null) throw new IllegalStateException("Server already running");
URL url = getClass().getResource("/" + propertiesFile);
if (url==null) throw new IllegalArgumentException("Could not resolve properties file "+propertiesFile);
final Jetty6WebServer jettyWebServer = new Jetty6WebServer() {
@Override
protected void startJetty() {
final Server jettyServer = getJetty();
jettyServer.setStopAtShutdown(true);
final JettyStartupListener startupListener = new JettyStartupListener();
jettyServer.getServer().addLifeCycleListener(startupListener);
// System.err.println("jetty is started before notification " + jettyServer.isStarted());
super.startJetty();
startupListener.await();
jettyServer.removeLifeCycleListener(startupListener);
// System.err.println("jetty is started after notification " + jettyServer.isStarted());
}
@Override
public void stop() {
final Server jettyServer = getJetty();
final JettyStartupListener listener = new JettyStartupListener();
jettyServer.getServer().addLifeCycleListener(listener);
super.stop();
listener.await();
jettyServer.removeLifeCycleListener(listener);
}
};
neoServer = new CommunityNeoServer(new PropertyFileConfigurator(new File(url.getPath()))) {
@Override
protected int getWebServerPort() {
return port;
}
@Override
protected StartupHealthCheck createHealthCheck() {
return new StartupHealthCheck();
}
@Override
protected Database createDatabase() {
return new WrappingDatabase(graphDatabase);
}
@Override
protected WebServer createWebServer() {
return jettyWebServer;
}
@Override
protected Iterable<ServerModule> createServerModules() {
return asList(new RESTApiModule(webServer,database,configurator.configuration()),new ThirdPartyJAXRSModule(webServer,configurator));
}
};
neoServer.start();
}
public void stop() {
try {
neoServer.stop();
} catch(Exception e) {
System.err.println("Error stopping server: "+e.getMessage());
}
neoServer=null;
}
public int getPort() {
return port;
}
public String getHostname() {
return hostname;
}
public LocalTestServer withPropertiesFile(String propertiesFile) {
this.propertiesFile = propertiesFile;
return this;
}
public Database getDatabase() {
return neoServer.getDatabase();
}
public URI baseUri() {
return neoServer.baseUri();
}
public void cleanDb() {
Neo4jDatabaseCleaner cleaner = new Neo4jDatabaseCleaner(getGraphDatabase());
cleaner.cleanDb();
}
public GraphDatabaseService getGraphDatabase() {
return getDatabase().graph;
}
private static class JettyStartupListener implements LifeCycle.Listener {
CountDownLatch latch=new CountDownLatch(1);
public void await() {
try {
latch.await(10, TimeUnit.SECONDS);
} catch(InterruptedException ie) {
System.err.println("ERROR startup took too long - await()");
throw new RuntimeException("Jetty did not start correctly",ie);
}
}
@Override
public void lifeCycleStarting(LifeCycle event) {
System.err.println("STARTING");
}
@Override
public void lifeCycleStarted(LifeCycle event) {
System.err.println("STARTED");
latch.countDown();
}
@Override
public void lifeCycleFailure(LifeCycle event, Throwable cause) {
System.out.println("FAILURE "+cause.getMessage());
latch.countDown();
throw new RuntimeException(cause);
}
@Override
public void lifeCycleStopping(LifeCycle event) {
System.err.println("STOPPING");
}
@Override
public void lifeCycleStopped(LifeCycle event) {
System.err.println("STOPPED");
latch.countDown();
}
}
}

View File

@@ -30,22 +30,33 @@ import org.neo4j.graphdb.Relationship;
import org.neo4j.rest.graphdb.ExecutingRestRequest;
import org.neo4j.rest.graphdb.RequestResult;
import org.neo4j.rest.graphdb.RestRequest;
import org.neo4j.server.NeoServer;
import org.neo4j.server.WrappingNeoServerBootstrapper;
import org.neo4j.server.configuration.Configurator;
import org.neo4j.server.configuration.PropertyFileConfigurator;
import org.neo4j.server.configuration.ServerConfigurator;
import org.neo4j.test.ImpermanentGraphDatabase;
import org.springframework.data.neo4j.rest.SpringRestGraphDatabase;
import static org.junit.Assert.assertEquals;
public class RestTestBase {
protected static ImpermanentGraphDatabase db;
protected SpringRestGraphDatabase restGraphDatabase;
private static final String HOSTNAME = "127.0.0.1";
public static final int PORT = 7470;
protected static LocalTestServer neoServer = new LocalTestServer(HOSTNAME,PORT).withPropertiesFile("test-db.properties");
protected static NeoServer neoServer = null;
public static final String SERVER_ROOT_URI = "http://" + HOSTNAME + ":" + PORT + "/db/data/";
@BeforeClass
public static void startDb() throws Exception {
BasicConfigurator.configure();
neoServer.start();
db = new ImpermanentGraphDatabase();
final ServerConfigurator configurator = new ServerConfigurator(db);
configurator.configuration().setProperty(Configurator.WEBSERVER_PORT_PROPERTY_KEY,PORT);
final WrappingNeoServerBootstrapper bootstrapper = new WrappingNeoServerBootstrapper(db, configurator);
bootstrapper.start();
neoServer = bootstrapper.getServer();
tryConnect();
}
@@ -72,7 +83,8 @@ public class RestTestBase {
}
public static void cleanDb() {
neoServer.cleanDb();
new Neo4jDatabaseCleaner(db).cleanDb();
//db.cleanContent(true);
}
@AfterClass
@@ -81,7 +93,7 @@ public class RestTestBase {
}
public GraphDatabaseService getGraphDatabase() {
return neoServer.getGraphDatabase();
return db;
}

View File

@@ -20,22 +20,30 @@ package org.springframework.data.neo4j.rest.support;
import java.net.URISyntaxException;
import org.apache.log4j.BasicConfigurator;
import org.neo4j.server.NeoServer;
import org.neo4j.server.WrappingNeoServerBootstrapper;
import org.neo4j.server.configuration.Configurator;
import org.neo4j.server.configuration.ServerConfigurator;
import org.neo4j.test.ImpermanentGraphDatabase;
import org.springframework.data.neo4j.core.GraphDatabase;
import org.springframework.data.neo4j.rest.SpringRestGraphDatabase;
public class RestTestHelper
{
protected SpringRestGraphDatabase graphDb;
private static final String HOSTNAME = "localhost";
private static final int PORT = 7470;
private static LocalTestServer neoServer;
private static NeoServer neoServer;
private static final String SERVER_ROOT_URI = "http://" + HOSTNAME + ":" + PORT + "/db/data/";
private static ImpermanentGraphDatabase db;
public void startServer() throws Exception {
BasicConfigurator.configure();
neoServer = new LocalTestServer(HOSTNAME,PORT).withPropertiesFile("test-db.properties");
neoServer.start();
db = new ImpermanentGraphDatabase();
final ServerConfigurator configurator = new ServerConfigurator(db);
configurator.configuration().setProperty(Configurator.WEBSERVER_PORT_PROPERTY_KEY,PORT);
final WrappingNeoServerBootstrapper bootstrapper = new WrappingNeoServerBootstrapper(db, configurator);
bootstrapper.start();
neoServer = bootstrapper.getServer();
}
public GraphDatabase createGraphDatabase() throws URISyntaxException {
@@ -43,7 +51,7 @@ public class RestTestHelper
}
public void cleanDb() {
neoServer.cleanDb();
db.cleanContent(true);
}
public static void shutdownServer() {

View File

@@ -41,7 +41,7 @@ public class ServerPluginTests extends RestTestBase {
@BeforeClass
public static void init() {
new ProvidedClassPathXmlApplicationContext(neoServer.getGraphDatabase(), "Plugin-context.xml");
new ProvidedClassPathXmlApplicationContext(db, "Plugin-context.xml");
}
@Test

View File

@@ -18,12 +18,19 @@ package org.springframework.data.neo4j.rest.support;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import org.apache.commons.configuration.Configuration;
import org.apache.log4j.BasicConfigurator;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.neo4j.rest.graphdb.RequestResult;
import org.neo4j.server.NeoServer;
import org.neo4j.server.WrappingNeoServerBootstrapper;
import org.neo4j.server.configuration.Configurator;
import org.neo4j.server.configuration.ServerConfigurator;
import org.neo4j.server.configuration.ThirdPartyJaxRsPackage;
import org.neo4j.test.ImpermanentGraphDatabase;
import org.springframework.data.neo4j.server.SpringPluginInitializer;
import javax.ws.rs.POST;
@@ -31,10 +38,12 @@ import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.Collections;
import java.util.Set;
@Path( "/" )
public class SpringPluginInitializerTests extends SpringPluginInitializer implements TestInterface {
private LocalTestServer neoServer;
private NeoServer neoServer;
public SpringPluginInitializerTests() {
super( new String[]{"ServerTests-context.xml"}, expose("testObject", TestInterface.class) );
@@ -59,10 +68,19 @@ public class SpringPluginInitializerTests extends SpringPluginInitializer implem
@Before
public void setUp() throws Exception {
BasicConfigurator.configure();
neoServer = new LocalTestServer( HOSTNAME, PORT ).withPropertiesFile( "server-test-db.properties" );
neoServer.start();
ImpermanentGraphDatabase db = new ImpermanentGraphDatabase();
final ServerConfigurator configurator = new ServerConfigurator(db) {
@Override
public Set<ThirdPartyJaxRsPackage> getThirdpartyJaxRsClasses() {
return Collections.singleton(new ThirdPartyJaxRsPackage("org.springframework.data.neo4j.rest.support","/test"));
}
};
final Configuration configuration = configurator.configuration();
configuration.setProperty(Configurator.WEBSERVER_PORT_PROPERTY_KEY, PORT);
final WrappingNeoServerBootstrapper bootstrapper = new WrappingNeoServerBootstrapper(db, configurator);
touched=0;
bootstrapper.start();
neoServer = bootstrapper.getServer();
}
@After

View File

@@ -21,6 +21,7 @@ import org.neo4j.kernel.impl.core.KernelPanicEventGenerator;
import org.neo4j.kernel.impl.nioneo.store.FileSystemAbstraction;
import org.neo4j.kernel.impl.transaction.AbstractTransactionManager;
import org.neo4j.kernel.impl.transaction.TransactionManagerProvider;
import org.neo4j.kernel.impl.transaction.TransactionStateFactory;
import org.neo4j.kernel.impl.transaction.TxHook;
import org.neo4j.kernel.impl.transaction.XaDataSourceManager;
import org.neo4j.kernel.impl.util.StringLogger;
@@ -36,7 +37,7 @@ public class SpringProvider extends TransactionManagerProvider
}
@Override
public AbstractTransactionManager loadTransactionManager(String txLogDir, XaDataSourceManager xaDataSourceManager, KernelPanicEventGenerator kpe, TxHook rollbackHook, StringLogger msgLog, FileSystemAbstraction fileSystem) {
return new SpringServiceImpl();
public AbstractTransactionManager loadTransactionManager(String s, XaDataSourceManager xaDataSourceManager, KernelPanicEventGenerator kernelPanicEventGenerator, TxHook txHook, StringLogger stringLogger, FileSystemAbstraction fileSystemAbstraction, TransactionStateFactory transactionStateFactory) {
return new SpringServiceImpl(transactionStateFactory);
}
}

View File

@@ -16,13 +16,17 @@
package org.springframework.data.neo4j.transaction;
import org.neo4j.kernel.impl.core.TransactionState;
import org.neo4j.kernel.impl.transaction.AbstractTransactionManager;
import org.neo4j.kernel.impl.transaction.TransactionStateFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.jta.JtaTransactionManager;
import javax.transaction.*;
import java.util.Map;
import java.util.WeakHashMap;
/**
* @author Chris Gioran
@@ -34,8 +38,12 @@ class SpringServiceImpl extends AbstractTransactionManager
private TransactionManager delegate;
SpringServiceImpl()
private final Map<Transaction, TransactionState> states = new WeakHashMap<Transaction, TransactionState>();
private final TransactionStateFactory stateFactory;
SpringServiceImpl(TransactionStateFactory stateFactory)
{
this.stateFactory = stateFactory;
}
@Override
@@ -47,6 +55,28 @@ class SpringServiceImpl extends AbstractTransactionManager
}
}
@Override
public void doRecovery() throws Throwable {
}
@Override
public TransactionState getTransactionState() {
try
{
TransactionState state = states.get( getTransaction() );
return state != null ? state : TransactionState.NO_STATE;
}
catch ( SystemException e )
{
throw new RuntimeException( e );
}
}
@Override
public int getEventIdentifier() {
return 0;
}
@Override
public void start() throws Throwable {
@@ -54,19 +84,23 @@ class SpringServiceImpl extends AbstractTransactionManager
@Override
public void shutdown() throws Throwable {
states.clear();
}
public void begin() throws NotSupportedException, SystemException
{
delegate.begin();
Transaction tx = getTransaction();
states.put(tx, stateFactory.create(tx));
}
public void commit() throws RollbackException, HeuristicMixedException,
HeuristicRollbackException, SecurityException,
IllegalStateException, SystemException
{
Transaction tx = getTransaction();
delegate.commit();
states.remove(tx);
}
public int getStatus() throws SystemException
@@ -88,7 +122,9 @@ class SpringServiceImpl extends AbstractTransactionManager
public void rollback() throws IllegalStateException, SecurityException,
SystemException
{
Transaction tx = getTransaction();
delegate.rollback();
states.remove(tx);
}
public void setRollbackOnly() throws IllegalStateException, SystemException

View File

@@ -17,7 +17,6 @@
<properties>
<validation>1.0.0.GA</validation>
<querydsl>2.9.0</querydsl>
</properties>
<dependencies>
@@ -196,6 +195,10 @@
<artifactId>blueprints-neo4j-graph</artifactId>
<version>${blueprints.version}</version>
<exclusions>
<exclusion>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-management</artifactId>
</exclusion>
<exclusion>
<groupId>org.neo4j</groupId>
<artifactId>neo4j</artifactId>

View File

@@ -77,12 +77,21 @@ public abstract class Neo4jHelper {
final GlobalGraphOperations globalGraphOperations = GlobalGraphOperations.at(graphDatabaseService);
for (Node node : globalGraphOperations.getAllNodes()) {
for (Relationship rel : node.getRelationships(Direction.OUTGOING)) {
rel.delete();
try {
rel.delete();
} catch(IllegalStateException ise) {
if (!ise.getMessage().contains("since it has already been deleted")) throw ise;
}
}
}
for (Node node : globalGraphOperations.getAllNodes()) {
if (includeReferenceNode || !graphDatabaseService.getReferenceNode().equals(node)) {
node.delete();
try {
node.delete();
} catch(IllegalStateException ise) {
if (!ise.getMessage().contains("since it has already been deleted")) throw ise;
}
}
}
}

View File

@@ -100,7 +100,7 @@ public class DataGraphNamespaceHandlerTests {
public void injectionForCodeConfiguredExistingGraphDatabaseService() {
assertInjected("-code");
}
@Test
@Test @Ignore("BeanCreationException DATAGRAPH-354")
public void injectionForBasePackageOfEntities() {
Config config = assertInjected("-entities");
Collection<Neo4jPersistentEntityImpl<?>> entities = config.mappingContext.getPersistentEntities();
@@ -123,7 +123,7 @@ public class DataGraphNamespaceHandlerTests {
Assert.assertNotNull("template", template);
AbstractGraphDatabase graphDatabaseService = (AbstractGraphDatabase) template.getGraphDatabaseService();
File directory = new File("target", "config-test");
Assert.assertEquals("store-dir", directory.getAbsolutePath(),graphDatabaseService.getStoreDir());
Assert.assertEquals("store-dir", directory.getPath(),graphDatabaseService.getStoreDir());
Assert.assertNotNull("graphDatabaseService",config.graphDatabaseService);
Assert.assertNotNull("transactionManager",config.transactionManager);
config.graphDatabaseService.shutdown();

View File

@@ -247,7 +247,7 @@ public class GraphRepositoryTests {
Page<Person> teamMemberPage1 = personRepository.findAllTeamMembersPaged(testTeam.sdg, null);
assertEquals(new HashSet(asList(testTeam.david, testTeam.emil, testTeam.michael)), addToCollection(teamMemberPage1, new HashSet()));
assertThat(teamMemberPage1.isFirstPage(), is(true));
assertThat(teamMemberPage1.isLastPage(), is(false));
assertThat(teamMemberPage1.isLastPage(), is(true));
}
@Test @Transactional
@@ -392,7 +392,7 @@ public class GraphRepositoryTests {
assertEquals(root.getId(),p2.getRoot().getId());
}
@Test
@Test @Transactional
public void testUseInterfaceAsPersistentEntity() {
final List<Being> beings = beingRepository.findAll().as(List.class);
assertEquals(3,beings.size());

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d %5p %40.40c:%4L - %m%n</pattern>
</encoder>
</appender>
<!--
<logger name="org.springframework" level="debug" />
-->
<root level="error">
<appender-ref ref="console" />
</root>
</configuration>