6 Replies Latest reply on Apr 5, 2006 3:02 PM by manik

    CacheStoreInterceptor -- how is putDataEraseMethodLocal hand

    genman


      The following test for a CacheLoader

       public void testPut3() throws CacheException {
       final String NODE="/a/b/c";
       final String KEY="key";
       cache.remove(NODE);
       addDelay();
       Map m = new HashMap();
       m.put("a", "b");
       m.put("c", "d");
       Map m2 = new HashMap();
       m2.put("e", "f");
       m2.put("g", "h");
       cache.put(NODE, m);
       assertEquals(m, cache.get(NODE).getData());
       cache.evict(Fqn.fromString(NODE));
       assertEquals(m, cache.get(NODE).getData());
       cache.evict(Fqn.fromString(NODE));
       cache.put(NODE, m2);
       assertEquals(m2, cache.get(NODE).getData());
       }


      Fails to run:
      expected:<{a=b, c=d}> but was:<{jboss:internal:uninitialized=null}>
      


      I went around and fixed CacheLoaderInterceptor to do the right thing (no, I don't think it was my own regression...) However, it then was giving me this:

      junit.framework.AssertionFailedError: expected:<{g=h, e=f}> but was:<{a=b, c=d, g=h, e=f}>
       at org.jboss.cache.loader.CacheLoaderTestsBase.testPut3(CacheLoaderTestsBase.java:154)
      


      It appears to be an issue with how putDataEraseMethodLocal is treated exactly the same as putDataMethodLocal. Basically, the old values are not replaced. The "easy" fix is to do "convertMethodCallToModification" and apply the changes as a modification list.

      Anyway, I'm opening another issue on this, and should have a patch in a bit.


        • 1. Re: CacheStoreInterceptor -- how is putDataEraseMethodLocal
          genman


          Okay, this may be a doc issue instead, since the docs say:


          * Adds a new node to the tree and sets its data. If the node doesn not yet exist, it will be created.
          * Also, parent nodes will be created if not existent. If the node already has data, then the new data
          * will override the old one. If the node already existed, a nodeModified() notification will be generated.
          * Otherwise a nodeCreated() motification will be emitted.
          */
          public void put(Fqn fqn, Map data) throws CacheException


          But in fact the call is:
           GlobalTransaction tx = getCurrentTransaction();
           MethodCall m = new MethodCall(putDataMethodLocal, new Object[]{tx, fqn, data, Boolean.TRUE});
           invokeMethod(m);
          


          What's the correct behavior here?

          Still, I wonder how come
          putDataEraseMethodLocal
          isn't being used like I would expect.

          • 2. Re: CacheStoreInterceptor -- how is putDataEraseMethodLocal
            manik

            Hmm, interesting - I would have expected it to call

            ... = new MethodCall(putDataMethodLocal, new Object[]{tx, fqn, data, Boolean.TRUE, Boolean.TRUE});
            


            Let me dig around and see why this is happening

            • 3. Re: CacheStoreInterceptor -- how is putDataEraseMethodLocal
              manik

              Again, it looks like this is how it has always been. I'd rather it changed as per my prevous posting and be true to the contract as per javadocs.

              • 4. Re: CacheStoreInterceptor -- how is putDataEraseMethodLocal
                genman


                To me, I would probably change the docs to match the behavior, since it's less likely to screw people over. And then, it's consistent with the CacheLoader.putAll() behavior. Then, create a putErase() or something method (!) for those that want the replacing behavior. Sounds like a bug report at least, let me know what you want. Thanks.

                • 5. Re: CacheStoreInterceptor -- how is putDataEraseMethodLocal
                  genman

                  It may also be the wording:


                  If the node already has data, then the new data will override the old one.


                  could mean, "If the node already has data, then the new keys and values will overwrite the existing keys and values." Notice it does say override not "overwrite".

                  • 6. Re: CacheStoreInterceptor -- how is putDataEraseMethodLocal
                    manik

                    Ben, Bela, what are your opinions on the semantics of this?