Reputation: 4335
I have written a webservice and would now like to write some unit tests for it. I stumbled across Michael Hunger's in memory server.
Due to the sparse documentation, I have a hard time setting up only one unit test. I cloned the project, included it in my workspace and added it as a dependency to my project.
In order to test my web service, I wrote this method to create an in-memory neo4j server:
@BeforeClass
public static void setupInMemoryServer()
{
CommunityBootstrapper s = new CommunityBootstrapper();
int status = -1;
try
{
status = s.start();
}
catch(Exception e)
{
System.out.println("could not start server");
e.printStackTrace();
System.out.println(e.getMessage());
System.out.println(e.getCause());
System.out.println(e.getLocalizedMessage());
}
System.out.println(hostAvailabilityCheck());
System.out.println("status = "+status);
}
public static boolean hostAvailabilityCheck() {
try (Socket s = new Socket("127.0.0.1", 7474)) {
return true;
} catch (IOException ex) {
System.out.println ("Neo server not online");
}
return false;
}
When I run this code, I get the following output:
Mai 29, 2014 10:13:17 PM org.neo4j.server.logging.Logger log SEVERE: Unable to upgrade database Mai 29, 2014 10:13:17 PM org.neo4j.server.logging.Logger log SEVERE: org.neo4j.server.ServerStartupException: Starting Neo4j Server failed: Startup failed due to preflight task [class org.neo4j.server.preflight.PerformUpgradeIfNecessary]: Unable to upgrade database at org.neo4j.server.AbstractNeoServer.start(AbstractNeoServer.java:218) at org.neo4j.server.Bootstrapper.start(Bootstrapper.java:87) at org.neo4j.server.Bootstrapper.start(Bootstrapper.java:74) at com.youtube.rest.status.test.CreateUserTest.setupInMemoryServer(CreateUserTest.java:26) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) Caused by: org.neo4j.server.preflight.PreflightFailedException: Startup failed due to preflight task [class org.neo4j.server.preflight.PerformUpgradeIfNecessary]: Unable to upgrade database at org.neo4j.server.AbstractNeoServer.runPreflightTasks(AbstractNeoServer.java:335) at org.neo4j.server.AbstractNeoServer.start(AbstractNeoServer.java:152) ... 19 more
Mai 29, 2014 10:13:17 PM org.neo4j.server.logging.Logger log SEVERE: Failed to start Neo Server on port [7474]
true
status = 1
Mai 29, 2014 10:13:17 PM org.neo4j.server.logging.Logger log WARNING: Failed to cleanly shutdown database. Mai 29, 2014 10:13:17 PM org.neo4j.server.logging.Logger log INFO: Successfully shutdown Neo Server on port [7474], database [unknown location]
I don't know why this happens since the server is built in memory and everything is (should) created temporarily. I neither understand, how database update conflicts can occur nor how to resolve them.
Upvotes: 1
Views: 895