Ejemplo n.º 1
0
  /**
   * Tests basic configuration with polling activation.
   *
   * @throws StreamException if test fails
   */
  @Test
  public void configureWithPollingTest() throws Exception {
    final AtomicInteger count = new AtomicInteger(0);

    final ContextBuilderConfigurator cfg =
        new ContextBuilderConfigurator() {

          /** {@inheritDoc} */
          @Override
          public int internalConfigure(final ContextBuilder ctxBuilder) {
            return 1;
          }

          /** {@inheritDoc} */
          @Override
          public String getTag() {
            return "test";
          }

          /** {@inheritDoc} */
          @Override
          protected Long getLastUpdateTimestampFor(final String path) throws StreamException {
            synchronized (ContextBuilderConfiguratorTest.class) {
              count.incrementAndGet();
              ContextBuilderConfiguratorTest.class.notify();
            }

            return System.currentTimeMillis();
          }
        };

    final ContextBuilder builder = Mockito.mock(ContextBuilder.class);
    cfg.configure(builder);

    synchronized (ContextBuilderConfiguratorTest.class) {
      ContextBuilderConfiguratorTest.class.wait(1500L);
    }

    Assert.assertEquals(count.intValue(), NumberUtils.TWO);
  }
Ejemplo n.º 2
0
  /**
   * Tests configurations when multiple and non-multiple executions are set.
   *
   * @throws StreamException if test fails
   */
  @Test
  public void configureMultipleTest() throws Exception {
    final AtomicInteger count = new AtomicInteger(0);
    final StringBuilder tagBuilder = new StringBuilder("test");

    final ContextBuilderConfigurator cfg =
        new ContextBuilderConfigurator() {

          /** {@inheritDoc} */
          @Override
          public int internalConfigure(final ContextBuilder ctxBuilder) {
            count.incrementAndGet();
            return -1;
          }

          /** {@inheritDoc} */
          @Override
          public String getTag() {
            return tagBuilder.toString();
          }

          /** {@inheritDoc} */
          @Override
          protected Long getLastUpdateTimestampFor(final String path) throws StreamException {
            return -1L;
          }
        };

    cfg.setMultipleConfigurations(Boolean.FALSE);
    cfg.configure(Mockito.mock(ContextBuilder.class));
    cfg.configure(Mockito.mock(ContextBuilder.class));
    cfg.configure(Mockito.mock(ContextBuilder.class));
    Assert.assertEquals(1, count.get());

    cfg.setMultipleConfigurations(Boolean.TRUE);
    cfg.configure(Mockito.mock(ContextBuilder.class));
    Assert.assertEquals(NumberUtils.TWO, count.get());

    cfg.setMultipleConfigurations(Boolean.FALSE);
    tagBuilder.append("1");
    cfg.configure(Mockito.mock(ContextBuilder.class));
    tagBuilder.append("1");
    cfg.configure(Mockito.mock(ContextBuilder.class));
    tagBuilder.append("1");
    cfg.configure(Mockito.mock(ContextBuilder.class));
    tagBuilder.append("1");
    cfg.configure(Mockito.mock(ContextBuilder.class));
    Assert.assertEquals(NumberUtils.SIX, count.get());
  }