Can not explore database created by an embedded neo4j - neo4j

I encounter a strange problem.
I created an database using embedded neo4j whose path is "/Users/bondwong/Documents/workspace/pamela/target/data/pamela.db".
Here is the Spring configuration:
<bean id="graphDbBuilder" factory-bean="graphDbFactory"
factory-method="newEmbeddedDatabaseBuilder">
<constructor-arg value="target/data/pamela.db" />
</bean>
Then I changed this line of neo4j-server.properties:
org.neo4j.server.database.location=/Users/bondwong/Documents/workspace/pamela/target/data/pamela.db
After that, I used curl to test my system, which showed all is good. Here is the result of getting a node whose id is 9:
However, when I fired up the server, and use the browser to see the data, nothing shows up:
Here is the location, it is the same as the one in the Spring XML configuration file:
Here is the :sysinfo result:
Here is the jUnit test and its result, showing that it actually insert the data:
package repositoryTest;
import static org.junit.Assert.*;
import java.util.HashMap;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import com.bond.pamela.domain.Diary;
import com.bond.pamela.domain.factory.DiaryFactory;
import com.bond.pamela.persistence.DirayRepository;
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration({ "/applicationContext.xml" })
public class DiaryRepositoryTest {
#Autowired
DirayRepository repository;
#Test
#Transactional
public void testSaveDiary() {
Diary diary = (Diary) DiaryFactory.getInstance().create(
new HashMap<String, Object>());
repository.save(diary);
Diary retrivedDiary = repository.findOne(diary.getGraphId());
assertEquals(diary, retrivedDiary);
}
}
I think it should work, someone knows what is wrong? and how to fix it. Thx!

You can write your java code as server extension
or use WrappingBootstrapper for the time being.
Or rather use ServerControls from Neo4j-Harness for testing
When creating the data, are you sure you committed the transaction correctly?
Transaction tx = db.beginTx();
// create data
tx.success();
tx.close();
or better
try (Transaction tx = db.beginTx()) {
// create data
tx.success();
}

Related

Micronoaut ServerStartupEvent callback not called in startup?

Just started to experiment with MN M3. Created a minimal Groovy service with the following code:
package test2
import groovy.transform.CompileStatic
import io.micronaut.context.event.ApplicationEventListener
import io.micronaut.runtime.Micronaut
import io.micronaut.runtime.server.event.ServerStartupEvent
#Singleton
#CompileStatic
class Application implements ApplicationEventListener<ServerStartupEvent> {
static void main(String[] args) {
println "Start"
Micronaut.run(Application.class)
}
#Override
void onApplicationEvent(ServerStartupEvent event) {
println "Boo!"
}
}
I get the "Start" but the startup event callback is never called:
Start
10:35:54.066 [main] INFO io.micronaut.runtime.Micronaut - Startup
completed in 897ms. Server Running: http://localhost:32034
I think this is the appropriate way to deal with initialization in MN?
Turns out Groovy has its own #Singleton annotation which was used by default. You need to import:
import javax.inject.Singleton
Might be a good idea to emphasize this somewhere in the docs.

New assignment to collection-type class field absent from flow program with Rascal, unlike to local variables

Consider the following Java code:
import java.util.LinkedList;
import java.util.List;
class Library {
List<String> loans = new LinkedList<>();
public List<String> searchUser(String name) {
List<String> usersFound = new LinkedList<>();
return loans;
}
}
and the following Rascal module:
module Mwe
import lang::java::flow::JavaToObjectFlow;
import lang::java::jdt::m3::AST;
import IO;
void m() {
ast = createAstFromEclipseFile(|project://test/src/test.java|, true);
fp = createOFG({ast});
print(fp);
}
The resulting flow program will be:
flowProgram({
attribute(|java+field:///Library/loans|),
method(|java+method:///Library/searchUser(java.lang.String)|,[|java+parameter:///Library/searchUser(java.lang.String)/scope(name)/scope(0)/name|]),
constructor(|java+constructor:///Library/Library()|,[])
},{
assign(|java+method:///Library/searchUser(java.lang.String)/return|,|id:///|,|java+field:///Library/loans|),
newAssign(|java+variable:///Library/searchUser(java.lang.String)/usersFound|,|java+class:///java/util/LinkedList|,|java+constructor:///java/util/LinkedList/LinkedList()|,[])
})
So, there is a new assignment of LinkedList to usersFound, but nothing comparable for loans. Why would that happen? Is that the intended behaviour?
Just checked the implementation, the field initializers are not included in the getStatements function (see lang::java::flow::JavaToObjectFlow on line 169). Similarly the static initializers of a class are ignored.
The best way forward would be to either report it as a bug, or fix it and turn it into a pull-request. (pull request is the quickest way to getting it fixed on unstable)
As a possible, yet work intensive workaround you rewrite the AST to put the field initializers inside all existing constructors (or add a constructor if there is none).

Struts2 NotSerializableException occurs with ExecuteAndWaitInterceptor

We are running Struts 2.5.14.1 and working on externalizing Tomcat session state. This requires Serializable sessions. However, our Action with the ExecuteAndWait interceptor fails. Since our original code was quite complex I wrote a simpler one below which demonstrates the exact same behavior.
The simple action is shown here:
package com.sentrylink.web.actions;
import java.util.concurrent.TimeUnit;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.InterceptorRefs;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import com.opensymphony.xwork2.ActionSupport;
#SuppressWarnings("serial")
#Results({
#Result(name="wait", location="/"),
#Result(name=ActionSupport.SUCCESS, location="/WEB-INF/content/messagePage.jsp"),
})
#InterceptorRefs({
#InterceptorRef("webStack"),
#InterceptorRef("execAndWait")
})
public class TestExecuteAndWait extends ActionSupport {
public String execute() throws Exception {
TimeUnit.SECONDS.sleep(10);
return SUCCESS;
}
}
Running this gives
WARNING: Cannot serialize session attribute __execWaittest-execute-and-wait for session 74CDB9F8D00BBC697030AFC6978E94F6
java.io.NotSerializableException: com.opensymphony.xwork2.inject.ContainerImpl$ConstructorInjector
It appears that Struts is pulling in an unwanted item for serialization. It may be related to the bug described here, although the fix put in for that bug appears to be present in 2.5.14.1 (not surprisingly, since that fix was in 2013).
I suspect this is a bug in the framework, but before I go ahead and file a report, and figure out a workaround for myself, I thought I would see if anyone had a solution or had ever gotten ExecuteAndWait to work with serialized sessions.

JMockit Mocking java.net.URL causes test not run

I'm using the newest versions of junit and jmockit and Oracle JDK 7 in Eclipse. When I try to mock java.net.URL my test won't run.
I have in my code something like:
URL url = new URL("String representing the url.");
So I figured in my test I could mock this like so:
#Mocked private URL _url;
Since this works for pretty much everything else, I know URL is final but I thought that was okay with JMockit.
When I run a test class with the above mock in eclipse the result is a grey line(as opposed to green or red.) So I'm assuming some kind of initialization problem. The rest of the test or code doesn't seem to matter, no matter what I put that #Mocked line in, this happens.
A workaround would be great, an explanation of what is actually causing this would be even better. Any help is definitely appreciated! Thanks!
Quick example. This actually gives an exception, but I think it is basically doing the same thing I have seen:
package demo;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
public class Connecting {
public boolean connectionattempt() throws IOException {
URL url = new URL("http://nowhere/");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
if (connection != null) {
return true;
}
else {
return false;
}
}
}
And this test:
package demo;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import org.junit.Test;
import mockit.Expectations;
import mockit.Mocked;
import mockit.Tested;
public class TestConnecting {
#Mocked URL _url;
#Mocked HttpURLConnection _connection;
#Tested Connecting _sut;
#Test
public void testConnect() throws IOException {
new Expectations() { {
_url.openConnection(); result = _connection;
} };
assertEquals(true, _sut.connectionattempt());
}
}
and the stack trace:
java.lang.NoClassDefFoundError: org/eclipse/jdt/internal/junit/runner/TestReferenceFailure
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestListener.testFailure(JUnit4TestListener.java:91)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestListener.testFailure(JUnit4TestListener.java:69)
at org.junit.runner.notification.RunNotifier$4.notifyListener(RunNotifier.java:139)
at org.junit.runner.notification.RunNotifier$SafeNotifier.run(RunNotifier.java:61)
at org.junit.runner.notification.RunNotifier.fireTestFailures(RunNotifier.java:134)
at org.junit.runner.notification.RunNotifier.fireTestFailure(RunNotifier.java:128)
at org.junit.internal.runners.model.EachTestNotifier.addFailure(EachTestNotifier.java:23)
at org.junit.runners.ParentRunner.run(ParentRunner.java:315)
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:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
I executed the test on Eclipse Kepler SR2, IntelliJ IDEA 13.1, and Netbeans 8.0.1, using JMockit 1.13, JUnit 4.11, and Oracle JDK 1.7.0_67.
The test passes in every case, it's all green! So, I don't know what could possibly be the problem in your environment. Are you sure the "newest version" of JMockit (1.13 at this time) was the one actually used?

Grails request parameter type conversion

In my Grails app, I need to bind a request parameter to a Date field of a command object. In order to perform the String-to-Date conversion, one needs to register an appropriate PropertyEditor in grails-app\conf\spring\resources.groovy
I've added the following bean definiton:
import org.springframework.beans.propertyeditors.CustomDateEditor
import java.text.SimpleDateFormat
beans = {
paramDateEditor(CustomDateEditor, new SimpleDateFormat("dd/MM/yy"), true) {}
}
But I'm still getting an error:
java.lang.IllegalArgumentException: Could not parse date: Unparseable date: "04/01/99"]
I think there's probably just something wrong with the way I've defined the bean, but I've no idea what?
The piece you are missing is registering of the new property editor. The following worked for me when I upgraded to Grails 1.1 and had to bind dates in the MM/dd/yyyy format.
grails-app/config/spring/resources.groovy:
beans = {
customPropertyEditorRegistrar(util.CustomPropertyEditorRegistrar)
}
src/groovy/util/CustomPropertyEditorRegistrar.groovy:
package util
import java.util.Date
import java.text.SimpleDateFormat
import org.springframework.beans.propertyeditors.CustomDateEditor
import org.springframework.beans.PropertyEditorRegistrar
import org.springframework.beans.PropertyEditorRegistry
public class CustomPropertyEditorRegistrar implements PropertyEditorRegistrar {
public void registerCustomEditors(PropertyEditorRegistry registry) {
registry.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("dd/MM/yy"), true));
}
}

Resources