Uploaded image for project: 'Tupelo'
  1. Tupelo
  2. TUP-274

Thing session refetch retains all values

XMLWordPrintableJSON

      Two thing sessions save different values for a single-valued property. AFTER multiple saves. when refetch is called in one session, older values are then kept (rather replacing the values with the new ones). Since getValue returns only one of the values, the wrong value is sometimes returned.

      Comment: you really do need the second thing session there or it works. What happens is that two values – one from each session – end up in the context on save.

      @Test
      public void testThingSessionRefetch() throws Exception{
      MemoryContext memoryContext = new MemoryContext();
      int oldValue = 5, newerValue = 6, newValue=7;
      Resource subject = Resource.uriRef("urn:test:/subject");
      Resource predicate = Resource.uriRef("urn:test:/predicate");

      ThingSession thingSession1 = new ThingSession(memoryContext);
      Thing thing1 = thingSession1.fetchThing(subject);
      thing1.setValue(predicate, oldValue);
      thingSession1.save();

      ThingSession thingSession2 = new ThingSession(memoryContext);
      Thing thing2 = thingSession2.fetchThing(subject);
      thing2.setValue(predicate, newValue);
      thingSession2.save();

      // shows it really is only the final value of a sequence of changes that gets written
      for (int i = 10; i < 15; i++)

      { thing1.setValue(predicate, i); thing1.save(); }

      thing1.refetch();

      // next snippet shows that there are multiple values landing in the context. One from each session. Once the very first save in the loop occurs this is multi-valued and stays that way.

      TripleMatcher tm = new TripleMatcher();
      tm.setSubject(subject);
      tm.setPredicate(predicate);
      memoryContext.perform(tm);
      RdfXml.write(tm.getResult(), System.out);

      // The actual check.
      System.out.println(thing1.getValues(predicate)); // should be one value
      assert thing1.getValues(predicate).size() == 1;
      assert thing1.getInt(predicate) == newValue;
      }

              futrelle Joe Futrelle (Inactive)
              jgaynor Jeffrey Gaynor
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved: