示例#1
0
  public void testStack() throws Exception {
    clazz = Stack.class;
    instance = clazz.newInstance();
    objManager.lookupOrCreate(instance);

    invokeMethod(
        clazz,
        instance,
        SerializationUtil.PUSH_SIGNATURE,
        new Class[] {Object.class},
        new Object[] {new Integer(1)});
    invokeMethod(clazz, instance, SerializationUtil.POP_SIGNATURE, new Class[] {}, new Object[] {});

    tcObject = (MockTCObject) objManager.lookupOrCreate(instance);
    history = tcObject.getHistory();
    assertEquals(2, history.size());

    call = (MockTCObject.MethodCall) history.get(0);
    assertEquals(SerializationUtil.ADD, call.method);
    assertEquals(new Integer(1), call.parameters[0]);

    call = (MockTCObject.MethodCall) history.get(1);
    assertEquals(SerializationUtil.REMOVE_AT, call.method);
    assertEquals(new Integer(0), call.parameters[0]);
  }
示例#2
0
  public void testHashSet() throws Exception {
    clazz = HashSet.class;
    instance = clazz.newInstance();
    objManager.lookupOrCreate(instance);
    int callCount = 0;
    int checkCount = 0;
    invokeMethod(
        clazz,
        instance,
        SerializationUtil.ADD_SIGNATURE,
        new Class[] {Object.class},
        new Object[] {new Integer(1)});
    callCount++;

    invokeMethod(
        clazz,
        instance,
        SerializationUtil.REMOVE_SIGNATURE,
        new Class[] {Object.class},
        new Object[] {new Integer(1)});

    callCount++;

    invokeMethod(
        clazz, instance, SerializationUtil.CLEAR_SIGNATURE, new Class[] {}, new Object[] {});
    callCount++;

    tcObject = (MockTCObject) objManager.lookupOrCreate(instance);
    history = tcObject.getHistory();

    assertEquals(callCount, history.size());

    call = (MockTCObject.MethodCall) history.get(checkCount++);
    assertEquals(SerializationUtil.ADD, call.method);
    assertEquals(new Integer(1), call.parameters[0]);

    call = (MockTCObject.MethodCall) history.get(checkCount++);
    assertEquals(SerializationUtil.REMOVE, call.method);
    assertEquals(new Integer(1), call.parameters[0]);

    call = (MockTCObject.MethodCall) history.get(checkCount++);
    assertEquals(SerializationUtil.CLEAR, call.method);
    assertEquals(0, call.parameters.length);
  }
示例#3
0
  public void testHashtable() throws Exception {
    clazz = Hashtable.class;
    instance = clazz.newInstance();

    objManager.lookupOrCreate(instance);
    invokeMethod(
        clazz,
        instance,
        SerializationUtil.PUT_SIGNATURE,
        new Class[] {Object.class, Object.class},
        new Object[] {new Integer(1), new Integer(2)});
    invokeMethod(
        clazz,
        instance,
        SerializationUtil.REMOVE_KEY_SIGNATURE,
        new Class[] {Object.class},
        new Object[] {new Integer(1)});
    invokeMethod(
        clazz, instance, SerializationUtil.CLEAR_SIGNATURE, new Class[] {}, new Object[] {});
    tcObject = (MockTCObject) objManager.lookupOrCreate(instance);
    history = tcObject.getHistory();
    assertEquals(3, history.size());

    call = (MockTCObject.MethodCall) history.get(0);
    assertEquals(SerializationUtil.PUT, call.method);
    params = call.parameters;
    assertEquals(new Integer(1), params[0]);
    assertEquals(new Integer(2), params[1]);
    assertEquals(2, params.length);

    call = (MockTCObject.MethodCall) history.get(1);
    assertEquals(SerializationUtil.REMOVE, call.method);
    params = call.parameters;
    assertEquals(new Integer(1), params[0]);
    assertEquals(1, params.length);

    call = (MockTCObject.MethodCall) history.get(2);
    assertEquals(SerializationUtil.CLEAR, call.method);
    params = call.parameters;
    assertEquals(0, params.length);
  }
示例#4
0
  public void setUp() throws Exception {
    objManager = new TestClientObjectManager();
    objManager.setIsManaged(true);

    DSOClientConfigHelper config = configHelper();

    ClassProvider classProvider = new MockClassProvider();
    DSOContext context =
        DSOContextImpl.createContext(
            config,
            classProvider,
            new ManagerImpl(
                false, objManager, new MockTransactionManager(), config, classProvider, null));

    ClassProcessorHelper.setContext(Thread.currentThread().getContextClassLoader(), context);
  }
示例#5
0
  public void testLinkedList() throws Exception {
    // LinkedList
    clazz = LinkedList.class;
    instance = clazz.newInstance();
    objManager.lookupOrCreate(instance);
    invokeMethod(
        clazz,
        instance,
        SerializationUtil.ADD_SIGNATURE,
        new Class[] {Object.class},
        new Object[] {new Integer(1)});
    invokeMethod(
        clazz,
        instance,
        SerializationUtil.ADD_AT_SIGNATURE,
        new Class[] {int.class, Object.class},
        new Object[] {new Integer(0), new Integer(1)});
    LinkedList l = new LinkedList();
    l.add("Hello");
    l.add("world");
    invokeMethod(
        clazz,
        instance,
        SerializationUtil.ADD_ALL_AT_SIGNATURE,
        new Class[] {int.class, Collection.class},
        new Object[] {new Integer(0), l});

    invokeMethod(
        clazz,
        instance,
        SerializationUtil.ADD_ALL_SIGNATURE,
        new Class[] {Collection.class},
        new Object[] {l});
    invokeMethod(
        clazz,
        instance,
        SerializationUtil.ADD_FIRST_SIGNATURE,
        new Class[] {Object.class},
        new Object[] {new Integer(2)});
    invokeMethod(
        clazz,
        instance,
        SerializationUtil.ADD_LAST_SIGNATURE,
        new Class[] {Object.class},
        new Object[] {new Integer(3)});
    invokeMethod(
        clazz,
        instance,
        SerializationUtil.REMOVE_AT_SIGNATURE,
        new Class[] {int.class},
        new Object[] {new Integer(1)});
    invokeMethod(
        clazz,
        instance,
        SerializationUtil.REMOVE_SIGNATURE,
        new Class[] {Object.class},
        new Object[] {"Hello"});
    invokeMethod(
        clazz,
        instance,
        SerializationUtil.SET_SIGNATURE,
        new Class[] {int.class, Object.class},
        new Object[] {new Integer(1), new Integer(2)});
    invokeMethod(
        clazz, instance, SerializationUtil.CLEAR_SIGNATURE, new Class[] {}, new Object[] {});

    tcObject = (MockTCObject) objManager.lookupOrCreate(instance);
    history = tcObject.getHistory();
    assertEquals(12, history.size());

    call = (MockTCObject.MethodCall) history.get(0);
    assertEquals(SerializationUtil.ADD, call.method);
    assertEquals(new Integer(1), call.parameters[0]);

    call = (MockTCObject.MethodCall) history.get(1);
    assertEquals(SerializationUtil.ADD_AT, call.method);
    assertEquals(new Integer(0), call.parameters[0]);
    assertEquals(new Integer(1), call.parameters[1]);

    call = (MockTCObject.MethodCall) history.get(2);
    assertEquals(SerializationUtil.ADD_AT, call.method);
    assertEquals(new Integer(0), call.parameters[0]);
    assertEquals("Hello", call.parameters[1]);

    call = (MockTCObject.MethodCall) history.get(3);
    assertEquals(SerializationUtil.ADD_AT, call.method);
    assertEquals(new Integer(1), call.parameters[0]);
    assertEquals("world", call.parameters[1]);

    call = (MockTCObject.MethodCall) history.get(4);
    assertEquals(SerializationUtil.ADD_AT, call.method);
    assertEquals("Hello", call.parameters[1]);

    call = (MockTCObject.MethodCall) history.get(5);
    assertEquals(SerializationUtil.ADD_AT, call.method);
    assertEquals("world", call.parameters[1]);

    call = (MockTCObject.MethodCall) history.get(6);
    assertEquals(SerializationUtil.ADD_FIRST, call.method);
    assertEquals(new Integer(2), call.parameters[0]);

    call = (MockTCObject.MethodCall) history.get(7);
    assertEquals(SerializationUtil.ADD_LAST, call.method);
    assertEquals(new Integer(3), call.parameters[0]);

    call = (MockTCObject.MethodCall) history.get(8);
    assertEquals(SerializationUtil.REMOVE_AT, call.method);
    assertEquals(new Integer(1), call.parameters[0]);

    call = (MockTCObject.MethodCall) history.get(9);
    assertEquals(SerializationUtil.REMOVE, call.method);
    assertEquals("Hello", call.parameters[0]);

    call = (MockTCObject.MethodCall) history.get(10);
    assertEquals(SerializationUtil.SET, call.method);
    assertEquals(new Integer(1), call.parameters[0]);
    assertEquals(new Integer(2), call.parameters[1]);

    call = (MockTCObject.MethodCall) history.get(11);
    assertEquals(SerializationUtil.CLEAR, call.method);
    params = call.parameters;
    assertEquals(0, params.length);
  }
示例#6
0
  public void testVector() throws Exception {
    clazz = Vector.class;
    instance = clazz.newInstance();
    objManager.lookupOrCreate(instance);
    invokeMethod(
        clazz,
        instance,
        SerializationUtil.ADD_SIGNATURE,
        new Class[] {Object.class},
        new Object[] {new Integer(1)});
    invokeMethod(
        clazz,
        instance,
        SerializationUtil.ADD_AT_SIGNATURE,
        new Class[] {int.class, Object.class},
        new Object[] {new Integer(0), new Integer(1)});
    LinkedList l = new LinkedList();
    l.add("Hello");
    l.add("world");
    invokeMethod(
        clazz,
        instance,
        SerializationUtil.ADD_ALL_AT_SIGNATURE,
        new Class[] {int.class, Collection.class},
        new Object[] {new Integer(0), l});
    invokeMethod(
        clazz,
        instance,
        SerializationUtil.ADD_ALL_SIGNATURE,
        new Class[] {Collection.class},
        new Object[] {l});
    invokeMethod(
        clazz,
        instance,
        SerializationUtil.REMOVE_AT_SIGNATURE,
        new Class[] {int.class},
        new Object[] {new Integer(1)});
    invokeMethod(
        clazz,
        instance,
        SerializationUtil.SET_SIGNATURE,
        new Class[] {int.class, Object.class},
        new Object[] {new Integer(1), new Integer(2)});

    // This one is very important, this test that the parameter reversing logic works
    invokeMethod(
        clazz,
        instance,
        SerializationUtil.SET_ELEMENT_SIGNATURE,
        new Class[] {Object.class, int.class},
        new Object[] {new Integer(69), new Integer(1)});

    invokeMethod(
        clazz, instance, SerializationUtil.CLEAR_SIGNATURE, new Class[] {}, new Object[] {});

    tcObject = (MockTCObject) objManager.lookupOrCreate(instance);
    history = tcObject.getHistory();
    assertEquals(10, history.size());

    call = (MockTCObject.MethodCall) history.get(0);
    assertEquals(SerializationUtil.ADD, call.method);
    assertEquals(new Integer(1), call.parameters[0]);

    call = (MockTCObject.MethodCall) history.get(1);
    // Vector implementation calls insertElementAt() internally, hopefully this is constant over all
    // of time
    assertEquals(SerializationUtil.INSERT_AT, call.method);
    assertEquals(new Integer(0), call.parameters[0]);
    assertEquals(new Integer(1), call.parameters[1]);

    call = (MockTCObject.MethodCall) history.get(2);
    assertEquals(SerializationUtil.ADD_AT, call.method);
    assertEquals(new Integer(0), call.parameters[0]);
    assertEquals("Hello", call.parameters[1]);

    call = (MockTCObject.MethodCall) history.get(3);
    assertEquals(SerializationUtil.ADD_AT, call.method);
    assertEquals(new Integer(1), call.parameters[0]);
    assertEquals("world", call.parameters[1]);

    call = (MockTCObject.MethodCall) history.get(4);
    if (Vm.isIBM()) {
      // the IBM JDK delegates all add() method calls internally to addAt()
      assertEquals(SerializationUtil.ADD_AT, call.method);
      assertEquals(new Integer(4), call.parameters[0]);
      assertEquals("Hello", call.parameters[1]);
    } else {
      assertEquals(SerializationUtil.ADD, call.method);
      assertEquals("Hello", call.parameters[0]);
    }

    call = (MockTCObject.MethodCall) history.get(5);
    if (Vm.isIBM()) {
      // the IBM JDK delegates all add() method calls internally to addAt()
      assertEquals(SerializationUtil.ADD_AT, call.method);
      assertEquals(new Integer(5), call.parameters[0]);
      assertEquals("world", call.parameters[1]);
    } else {
      assertEquals(SerializationUtil.ADD, call.method);
      assertEquals("world", call.parameters[0]);
    }

    call = (MockTCObject.MethodCall) history.get(6);
    assertEquals(SerializationUtil.REMOVE_AT, call.method);
    assertEquals(new Integer(1), call.parameters[0]);

    call = (MockTCObject.MethodCall) history.get(7);
    assertEquals(SerializationUtil.SET, call.method);
    assertEquals(new Integer(1), call.parameters[0]);
    assertEquals(new Integer(2), call.parameters[1]);

    call = (MockTCObject.MethodCall) history.get(8);
    assertEquals(SerializationUtil.SET_ELEMENT, call.method);
    // These are supposed to be reversed
    assertEquals(new Integer(1), call.parameters[0]);
    assertEquals(new Integer(69), call.parameters[1]);

    call = (MockTCObject.MethodCall) history.get(9);
    assertEquals(SerializationUtil.CLEAR, call.method);
    params = call.parameters;
    assertEquals(0, params.length);
  }