To further simplify the example, taking out my REST services out of the 
picture, simply running the following code in a Java Oak app:

        DB database = new MongoClient("127.0.0.1", 27017).getDB("sling");
        DocumentNodeStore store = new 
DocumentMK.Builder().setMongoDB(database).getNodeStore();
        Repository repo = new Jcr(new Oak(store)).createRepository();
        
        Session session = repo.login( new SimpleCredentials("admin", 
"admin".toCharArray()) );
        Node root = session.getRootNode();
        Node child = root.addNode("myFolder", "nt:folder");
        session.save();

        // getResponseFromSling simply does a GET request to Sling to the node 
at path using HttpURLConnection and returns the resulting JSON
        System.out.println(getResponseFromSling("/myFolder");

This results in an error: java.io.FileNotFoundException: 
http://localhost:8080/myFolder.harray.infinity.json
        because it cannot get the inputStream from a Node that Sling doesn't 
think exists.

However, adding a two (2) second delay (by sleeping) before doing the GET 
request to Sling returns the correct JSON successfully. Again, this problem 
does NOT exist using Jackrabbit and Sling 7 (as opposed to Oak with MongoDB and 
Sling 8).

> From: [email protected]
> To: [email protected]
> Subject: RE: Sling retrieving out-of-date data
> Date: Tue, 1 Dec 2015 19:57:50 +0000
> 
> It is an Oak application and yes, it does manipulate the documents directly 
> without making REST calls to Sling. Much of it taken from 
> http://jackrabbit.apache.org/oak/docs/construct.html , here is what the code 
> may look like:
> 
> // REST service createChildFolder running on localhost:8040
> public void createChildFolder(String parentPath, String childName) {
>             DB database = new MongoClient("127.0.0.1", 27017).getDB("sling");
>             DocumentNodeStore store = new 
> DocumentMK.Builder().setMongoDB(database).getNodeStore();
>             Repository repo = new Jcr(new Oak(store)).createRepository();
>             SimpleCredentials creds = new SimpleCredentials("admin", 
> "admin".toCharArray());
>             Session session = (javax.jcr.Session) repository.login(creds);
>             Node parent = session.getRootNode().getNode(parentPath);
>             Node child = parent.addNode(childName, "sling:Folder");
>             session.save();
>             session.logout();
>             store.dispose();
> }
> 
> // Test case
> public void test1() {
>             //Make POST request to createChildFolder using HttpURLConnection
>             //Get back JSON response by making GET request to Sling at 
> localhost:8080 (which is persisted by MongoDB at 127.0.0.1:27017) using 
> HttpURLConnection
>             //Compare resulting JSON from GET request with one that has child 
> node at parent
> }
> 
> Thanks,
> H
> 
> > From: [email protected]
> > Date: Tue, 1 Dec 2015 19:43:10 +0000
> > Subject: Re: Sling retrieving out-of-date data
> > To: [email protected]
> > 
> > Are you saying that you have a non-Oak application which connects directly
> > to MongoDB and manipulates the documents?
> > 
> > On Tue, Dec 1, 2015 at 2:22 PM H K <[email protected]> wrote:
> > 
> > > Hi,
> > >
> > > Sure. In pseudocode, here it is:
> > >
> > > 1. Have Sling standalone running and have application that provides REST
> > > service createChildFolder (for example sake). Application connects to
> > > repository by using DocumentMK, as in the link from the OP post.
> > >
> > > 2. Call createChildFolder("pathToParent", "childName").
> > >
> > > 3. Make GET request to http://localhost:8080/pathToParent.infinity.json
> > >
> > > 4. Inspecting the JSON Object, expect there to be a child node in parent
> > > node but none are there. Test failed.
> > >
> > > However, if I let the thread sleep for 2 seconds after step 2, child
> > > exists in the JSON as wanted.
> > >
> > > Thanks,
> > > H
> > >
> > > > From: [email protected]
> > > > To: [email protected]
> > > > Subject: Re: Sling retrieving out-of-date data
> > > > Date: Tue, 1 Dec 2015 19:49:20 +0100
> > > >
> > > > On Tuesday 01 December 2015 11:37:42 H K wrote:
> > > > > Hi,
> > > >
> > > > Hi,
> > > >
> > > > > I'm currently using the Sling 8 standalone and it's connected to a
> > > MongoDB
> > > > > database. I've got an application which also connects to the same
> > > MongoDB
> > > > > database and writes/reads from it. The connection is done using
> > > DocumentMK,
> > > > > following the instructions at
> > > > > https://jackrabbit.apache.org/oak/docs/construct.html
> > > > >
> > > > > My problem is that when I write data to the repository through my
> > > > > application, Sling does not seem to get it fast enough, which may be
> > > > > because it is caching or because it only periodically checks to see if
> > > the
> > > > > data it has is up-to-date or not. For instance in my unit tests that
> > > test
> > > > > some of my REST services, I'm creating a child node somewhere and then
> > > > > doing a GET request to Sling to get back a JSON representing the
> > > updated
> > > > > parent. However, the returned result does not have the child in it. I
> > > know
> > > > > the changes are made because if I delay for two seconds before
> > > submitting
> > > > > the GET request, all works fine.
> > > > >
> > > > > This was not a problem using Sling 7 with Jackrabbit (instead of Oak)
> > > and
> > > > > connecting over RMI.
> > > > >
> > > > > Can someone provide some insight and/or a solution? Thanks!
> > > >
> > > > can you provide a minimal test case which resembles what you are doing?
> > > >
> > > > Regards,
> > > > O.
> > > >
> > >
>                                         
                                          

Reply via email to