コード例 #1
0
  /** @throws Exception */
  @Test
  public void testSerialization() throws Exception {
    // a simple worker that acquires a lock on page 5
    class Locker extends Thread {
      private final PageAccessSynchronizer sync;

      public Locker(PageAccessSynchronizer sync) {
        this.sync = sync;
      }

      @Override
      public void run() {
        sync.lockPage(5);
      }
    }

    // set up a synchronizer and lock page 5 with locker1
    final Duration timeout = Duration.seconds(30);
    final PageAccessSynchronizer sync = new PageAccessSynchronizer(timeout);
    Locker locker1 = new Locker(sync);

    final long start = System.currentTimeMillis();
    locker1.run();

    // make sure we can serialize the synchronizer

    final PageAccessSynchronizer sync2 = WicketObjects.cloneObject(sync);
    assertTrue(sync != sync2);

    // make sure the clone does not retain locks by attempting to lock page locked by locker1 in
    // locker2
    Locker locker2 = new Locker(sync2);
    locker2.run();
    assertTrue(Duration.milliseconds(System.currentTimeMillis() - start).lessThan(timeout));
  }
コード例 #2
0
 /** https://issues.apache.org/jira/browse/WICKET-6279 */
 @Test
 public void deserializeRemove() {
   AttributeModifier appender =
       AttributeModifier.append("class", AttributeModifier.VALUELESS_ATTRIBUTE_REMOVE);
   final AttributeModifier copy = WicketObjects.cloneObject(appender);
   final IModel<?> replaceModel = copy.getReplaceModel();
   assertThat(
       replaceModel.getObject(), is(sameInstance(AttributeModifier.VALUELESS_ATTRIBUTE_REMOVE)));
 }
コード例 #3
0
  @Test
  public void ensureSerializationDeserializationWorks() {
    WebMarkupContainer wmc = new WebMarkupContainer("id");

    Iterator<Component> iterator = wmc.iterator();

    addNChildren(wmc, NUMBER_OF_CHILDREN_FOR_A_MAP);
    assertThat(wmc.size(), is(NUMBER_OF_CHILDREN_FOR_A_MAP));

    assertThat(WicketObjects.cloneObject(wmc), is(not(nullValue())));

    removeNChildren(iterator, 1);
    assertThat(wmc.size(), is(NUMBER_OF_CHILDREN_FOR_A_MAP - 1));
    assertThat(WicketObjects.cloneObject(wmc), is(not(nullValue())));

    removeNChildren(iterator, NUMBER_OF_CHILDREN_FOR_A_MAP - 2);
    assertThat(WicketObjects.cloneObject(wmc), is(not(nullValue())));

    assertThat(wmc.size(), is(1));
    removeNChildren(iterator, 1);
    assertThat(wmc.size(), is(0));
    assertThat(WicketObjects.cloneObject(wmc), is(not(nullValue())));
  }