Package net.sf.joafip.store.service.objectfortest

Examples of net.sf.joafip.store.service.objectfortest.BobWithSerializeMethod


  @Override
  protected ObjectAndReferenced createObjectToSerialize() {
    BobWithSerializeMethod.writeMode = EnumSerializeMode.DEFAULT;
    BobWithSerializeMethod.readMode = EnumSerializeMode.DEFAULT;
    BobWithSerializeMethod.unshared = false;
    final BobWithSerializeMethod bobWithSerializeMethod = new BobWithSerializeMethod();
    final BobContainer bobContainer = new BobContainer();
    bobContainer.setObject1(bobWithSerializeMethod);
    bobWithSerializeMethod.setObject1(bobContainer);
    final Bob2 bob2 = new Bob2();
    bobWithSerializeMethod.setObject2(bob2);
    final Object[] referenceds = new Object[] { bobContainer, bob2 };
    return new ObjectAndReferenced(bobWithSerializeMethod, referenceds);
  }
View Full Code Here


    return new ObjectAndReferenced(bobWithSerializeMethod, referenceds);
  }

  @Override
  protected Object[] modifyObjectToSerialize(final Object object) {
    final BobWithSerializeMethod bobWithSerializeMethod = (BobWithSerializeMethod) object;
    final Object bobContainer = bobWithSerializeMethod.getObject1();
    final Bob1 bob1 = new Bob1();
    bobWithSerializeMethod.setObject2(bob1);
    return new Object[] { bobContainer, bob1 };
  }
View Full Code Here

    writeReadTest(true);
  }

  @Override
  protected ObjectAndReferenced createObjectToSerialize() {
    final BobWithSerializeMethod bobWithSerializeMethod =
    /**/new BobWithSerializeMethod();
    final Object[] referenceds;
    if (BobWithSerializeMethod.unshared) {
      final BobSerialize bobSerialize = new BobSerialize();
      bobSerialize.setData("hello".getBytes());
      bobSerialize.setIndex(1000);
      bobWithSerializeMethod.setObject1(bobSerialize);
      bobWithSerializeMethod.setObject2(bobSerialize);
      referenceds = new Object[] { bobSerialize, bobSerialize };
    } else {
      final Integer valueOf10 = Integer.valueOf(10);
      bobWithSerializeMethod.setObject1(valueOf10);
      final Integer valueOf100 = Integer.valueOf(100);
      bobWithSerializeMethod.setObject2(valueOf100);
      referenceds = new Object[] { valueOf10, valueOf100 };
    }
    bobWithSerializeMethod.setValue(1000);
    return new ObjectAndReferenced(bobWithSerializeMethod, referenceds);
  }
View Full Code Here

    return new ObjectAndReferenced(bobWithSerializeMethod, referenceds);
  }

  @Override
  protected void assertUnserialized(final Object unserialized) {
    final BobWithSerializeMethod unserializedBob = (BobWithSerializeMethod) unserialized;
    if (BobWithSerializeMethod.unshared) {
      final Object object1 = unserializedBob.getObject1();
      final Object object2 = unserializedBob.getObject2();
      assertEquals("must be equals", object1, object2);
      assertNotSame("must not be same instance", object1, object2);
    }
  }
View Full Code Here

    }
  }

  @Override
  protected Object[] modifyObjectToSerialize(final Object object) {
    final BobWithSerializeMethod bobWithSerializeMethod = (BobWithSerializeMethod) object;
    bobWithSerializeMethod.setObject2(new Bob1());
    return new Object[] { bobWithSerializeMethod.getObject1(),
        bobWithSerializeMethod.getObject2() };
  }
View Full Code Here

    BobWithSerializeMethod.unshared = false;
    /*
     * creation of object graph:
     * BobWithSerializeMethod->Bob1->Bob2,BobWithSerializeMethod->Integer
     */
    BobWithSerializeMethod bobContainer = new BobWithSerializeMethod();
    Bob1 bob1 = new Bob1();
    bobContainer.setObject1(bob1);
    bobContainer.setNotPrimitiveValue(Integer.valueOf(10));
    Bob2 bob2 = new Bob2();
    bob1.setBob2(bob2);
    store.setRoot(bobContainer);
    store.save(false, false);
    Map<DataRecordIdentifier, String> map = objectClassMap(new DataRecordIdentifier[] {});
    objectIoManager.clearObjectState();
    final String links1 = links(map);
    // objectIoManager.clearObjectState();
    // heapRecordableManager.clear();

    logger.debug("initial save");

    /*
     * assert garbage information after initial creation:
     * BobWithSerializeMethod->Bob1->Bob2,BobWithSerializeMethod->Integer
     */
    /*
     * BobWithSerializeMethod->Integer: no data record for basic
     */
    String expectedLinks = sortString(
    /**/"StoreRoot4 -> BobWithSerializeMethod\n" +
    /**/"BobWithSerializeMethod -> Bob1\n" +
    /**/"Bob1 -> Bob2\n");

    assertEquals("not expected link", expectedLinks, links1);

    /* number of to garbage */
    int numberToGarbage = toGarbageRecordManager.getNumberOfToGarbage();
    assertEquals("must not have object to garbage", 0, numberToGarbage);

    /* number of garbage candidate */
    int numberOfGarbageCandidate = garbageCandidateRecordManager
        .getNumberOfGarbageCandidate();
    assertEquals(MUST_NOT_HAVE_OBJECT_MARKED_GARBAGE_CANDIDATE, 0,
        numberOfGarbageCandidate);

    /* number of class name definition */
    final int initialNumberOfClassDef = classNameManager
        .getNumberOfClassDef();

    /* number of to visit */
    final int numberOfToVisit = toVisitRecordManager.getNumberOfToVisit();
    assertEquals(0, numberOfToVisit);

    /* number of visited */
    int numberOfVisited = visitedRecordManager.getNumberOfVisited();
    assertEquals(0, numberOfVisited);

    /* all data record */
    final int initialNumberOfDataRecord = dataManager
        .getNumberOfDataRecord();
    /*
     * read, check data record identifier, detach object, save
     */
    bobContainer = (BobWithSerializeMethod) store.readAndGetRoot();
    // x = store.getObjectIOManager().getObjectAndPersistInfoOfObject(
    // bobContainer);
    final DataRecordIdentifier idBobContainer = store
        .getDataRecordIdentifierAssociatedToObject(bobContainer);
    logger.debug("id bob container " + idBobContainer);
    assertNotNull("bobContainer must have associated data record",
        idBobContainer);

    bob1 = (Bob1) bobContainer.getObject1();
    final DataRecordIdentifier idBob1 = store
        .getDataRecordIdentifierAssociatedToObject(bob1);
    logger.debug("id bob1 " + idBob1);
    assertNotNull("bob1 must have associated data record", idBob1);

    bob2 = bob1.getBob2();
    final DataRecordIdentifier idBob2 = store
        .getDataRecordIdentifierAssociatedToObject(bob2);
    logger.debug("id bob2 " + idBob2);
    assertNotNull("bob2 must have associated data record", idBob2);

    assertDataRecord(new DataRecordIdentifier[] {
    /**/StoreForTest.IDENTIFIER_FOR_STORE_HEADER,/* store header */
    /**/StoreForTest.IDENTIFIER_FOR_ROOT,/* root record */
    /**/idBobContainer,/**/
    /**/idBob1,/**/
    /**/idBob2, /**/
    // /**/idNotPrimitive /**/
        }, new DataRecordIdentifier[] {});

    /*
     * break BobWithSerializeMethod->Bob1 on
     * BobWithSerializeMethod->Bob1->Bob2,BobWithSerializeMethod->Integer
     */
    /* id1 must be to garbage */
    bobContainer.setObject1(null);
    store.save(false, false);
    map = objectClassMap(new DataRecordIdentifier[] { idBob1 });
    objectIoManager.clearObjectState();
    final String links2 = links(map);
    logAllDataIdentifier();
    logger.debug("bob1 detached from bobContainer");

    /*
     * assert garbage information after detaching object
     */
    expectedLinks = sortString(
    /**/"StoreRoot4 -> BobWithSerializeMethod\n" +
    /**/"Bob1 -> Bob2\n");

    assertEquals("not expected link", expectedLinks, links2);
    String deleted = deleteLink(links1, links2);
    expectedLinks =
    /**/"BobWithSerializeMethod -> Bob1\n";
    assertEquals("not deleted expected", expectedLinks, deleted);

    /* number of to garbage */
    numberToGarbage = toGarbageRecordManager.getNumberOfToGarbage();
    assertEquals("must have object to garbage: bob1", 1, numberToGarbage);
    assertTrue("bob1 must be to garbage",
        toGarbageRecordManager.containsToGarbage(idBob1));

    /* number of garbage candidate */
    numberOfGarbageCandidate = garbageCandidateRecordManager
        .getNumberOfGarbageCandidate();
    // assertEquals(MUST_NOT_HAVE_OBJECT_MARKED_GARBAGE_CANDIDATE, 0,
    // numberOfGarbageCandidate);
    assertEquals(1, numberOfGarbageCandidate);
    assertTrue(garbageCandidateRecordManager.containsCandidate(idBob2));

    /* number of class name definition */
    final int numberOfClassDef = classNameManager.getNumberOfClassDef();
    assertEquals(initialNumberOfClassDef, numberOfClassDef);

    /* number of to visit */
    numberOfVisited = toVisitRecordManager.getNumberOfToVisit();
    assertEquals(0, numberOfToVisit);

    /* number of visited */
    numberOfVisited = visitedRecordManager.getNumberOfVisited();
    assertEquals(0, numberOfVisited);

    /* all data record */
    int numberOfDataRecord = dataManager.getNumberOfDataRecord();
    // assertEquals("number of data record must not change",
    // initialNumberOfDataRecord, numberOfDataRecord);
    /*
     * do garbage collection: bo1 and bob2 must be deleted, idbob1->idbob2
     * link must be removed
     */
    garbageSweep();
    logger.debug("garbaged");
    logAllDataIdentifier();
    final String links3 = links(map);
    expectedLinks = sortString(
    /**/"StoreRoot4 -> BobWithSerializeMethod\n");

    assertEquals("not expected link", expectedLinks, links3);

    numberToGarbage = toGarbageRecordManager.getNumberOfToGarbage();
    assertEquals("no more to garbage", 0, numberToGarbage);

    numberOfGarbageCandidate = garbageCandidateRecordManager
        .getNumberOfGarbageCandidate();
    assertEquals(MUST_NOT_HAVE_OBJECT_MARKED_GARBAGE_CANDIDATE, 0,
        numberOfGarbageCandidate);

    numberOfDataRecord = dataManager.getNumberOfDataRecord();
    assertEquals(
    /* decrease of 2 records for data, 2 records for link */
    "number of data record must decrease",
        initialNumberOfDataRecord - 2 - 2, numberOfDataRecord);

    assertDataRecord(new DataRecordIdentifier[] {
    /* expected */
    /**/Store.IDENTIFIER_FOR_STORE_HEADER,/* store header */
    /**/Store.IDENTIFIER_FOR_ROOT,/* root record */
    /* unexpected */
    /**/idBobContainer,/**/
    // /**/idNotPrimitive /**/
        }, new DataRecordIdentifier[] {
        /**/idBob1,/**/
        /**/idBob2 /**/
        });

    bobContainer = (BobWithSerializeMethod) store.readAndGetRoot();
    /*
     * break BobWithSerializeMethod->Integer this must change nothing
     */
    bobContainer.setNotPrimitiveValue(null);
    store.save(true, false);
    // logAllDataIdentifier();
    map = objectClassMap(new DataRecordIdentifier[] {});
    objectIoManager.clearObjectState();
    final String links4 = links(map);
View Full Code Here

TOP

Related Classes of net.sf.joafip.store.service.objectfortest.BobWithSerializeMethod

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.