コード例 #1
0
  private OperationContext sendReplicatePacket(final Packet packet, boolean lineUp) {
    if (!enabled) return null;
    boolean runItNow = false;

    OperationContext repliToken = OperationContextImpl.getContext(executorFactory);
    if (lineUp) {
      repliToken.replicationLineUp();
    }

    synchronized (replicationLock) {
      if (enabled) {
        pendingTokens.add(repliToken);
        replicatingChannel.send(packet);
      } else {
        // Already replicating channel failed, so just play the action now
        runItNow = true;
      }
    }

    // Execute outside lock

    if (runItNow) {
      repliToken.replicationDone();
    }

    return repliToken;
  }
コード例 #2
0
ファイル: UnitTestCase.java プロジェクト: igorhvr/hornetq
  @Override
  protected void setUp() throws Exception {
    super.setUp();

    OperationContextImpl.clearContext();

    deleteDirectory(new File(getTestDir()));

    InVMRegistry.instance.clear();

    // checkFreePort(TransportConstants.DEFAULT_PORT);

    previousThreads = Thread.getAllStackTraces();

    UnitTestCase.log.info("###### starting test " + this.getClass().getName() + "." + getName());
  }
コード例 #3
0
ファイル: UnitTestCase.java プロジェクト: igorhvr/hornetq
  protected void cleanupPools() {
    OperationContextImpl.clearContext();

    int invmSize = InVMRegistry.instance.size();
    if (invmSize > 0) {
      InVMRegistry.instance.clear();
      fail("invm registry still had acceptors registered");
    }

    if (AsynchronousFileImpl.getTotalMaxIO() != 0) {
      AsynchronousFileImpl.resetMaxAIO();
      Assert.fail("test did not close all its files " + AsynchronousFileImpl.getTotalMaxIO());
    }

    // We shutdown the global pools to give a better isolation between tests
    ServerLocatorImpl.clearThreadPools();
  }
コード例 #4
0
ファイル: ReplicationTest.java プロジェクト: hellojvm/hornetq
  @Test
  public void testExceptionSettingActionBefore() throws Exception {
    OperationContext ctx = OperationContextImpl.getContext(factory);

    ctx.storeLineUp();

    String msg = "I'm an exception";

    ctx.onError(HornetQExceptionType.UNBLOCKED.getCode(), msg);

    final AtomicInteger lastError = new AtomicInteger(0);

    final List<String> msgsResult = new ArrayList<String>();

    final CountDownLatch latch = new CountDownLatch(1);

    ctx.executeOnCompletion(
        new IOAsyncTask() {
          public void onError(final int errorCode, final String errorMessage) {
            lastError.set(errorCode);
            msgsResult.add(errorMessage);
            latch.countDown();
          }

          public void done() {}
        });

    Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));

    Assert.assertEquals(5, lastError.get());

    Assert.assertEquals(1, msgsResult.size());

    Assert.assertEquals(msg, msgsResult.get(0));

    final CountDownLatch latch2 = new CountDownLatch(1);

    // Adding the Task after the exception should still throw an exception
    ctx.executeOnCompletion(
        new IOAsyncTask() {
          public void onError(final int errorCode, final String errorMessage) {
            lastError.set(errorCode);
            msgsResult.add(errorMessage);
            latch2.countDown();
          }

          public void done() {}
        });

    Assert.assertTrue(latch2.await(5, TimeUnit.SECONDS));

    Assert.assertEquals(2, msgsResult.size());

    Assert.assertEquals(msg, msgsResult.get(0));

    Assert.assertEquals(msg, msgsResult.get(1));

    final CountDownLatch latch3 = new CountDownLatch(1);

    ctx.executeOnCompletion(
        new IOAsyncTask() {
          public void onError(final int errorCode, final String errorMessage) {}

          public void done() {
            latch3.countDown();
          }
        });

    Assert.assertTrue(latch2.await(5, TimeUnit.SECONDS));
  }