Esempio n. 1
0
 /**
  * @param sessionFactory
  * @param seconds
  * @param waitForSync
  * @param backup
  */
 public static void waitForRemoteBackup(
     ClientSessionFactoryInternal sessionFactory,
     int seconds,
     boolean waitForSync,
     final HornetQServer backup) {
   final HornetQServerImpl actualServer = (HornetQServerImpl) backup;
   final long toWait = seconds * 1000;
   final long time = System.currentTimeMillis();
   while (true) {
     if ((sessionFactory == null || sessionFactory.getBackupConnector() != null)
         && (actualServer.isRemoteBackupUpToDate() || !waitForSync)) {
       break;
     }
     if (System.currentTimeMillis() > (time + toWait)) {
       fail(
           "backup never started ("
               + actualServer.isStarted()
               + "), or never finished synchronizing ("
               + actualServer.isRemoteBackupUpToDate()
               + "), or sessionFactory!=null ? "
               + (sessionFactory != null)
               + " || sessionFactory.getBackupConnector()=="
               + (sessionFactory != null
                   ? sessionFactory.getBackupConnector()
                   : "not-applicable"));
     }
     try {
       Thread.sleep(100);
     } catch (InterruptedException e) {
       fail(e.getMessage());
     }
   }
 }
Esempio n. 2
0
 /**
  * Waits for backup to be in the "started" state and to finish synchronization with its live.
  *
  * @param sessionFactory
  * @param seconds
  * @throws Exception
  */
 protected void waitForBackup(ClientSessionFactoryInternal sessionFactory, int seconds)
     throws Exception {
   final HornetQServerImpl actualServer = (HornetQServerImpl) backupServer.getServer();
   if (actualServer.getConfiguration().isSharedStore()) {
     waitForServer(actualServer);
   } else {
     waitForRemoteBackup(sessionFactory, seconds, true, actualServer);
   }
 }
Esempio n. 3
0
  /**
   * This would recreate the scenario where a queue was duplicated
   *
   * @throws Exception
   */
  @Test
  public void testHangDuplicateQueues() throws Exception {
    final Semaphore blocked = new Semaphore(1);
    final CountDownLatch latchDelete = new CountDownLatch(1);
    class MyQueueWithBlocking extends QueueImpl {

      /**
       * @param id
       * @param address
       * @param name
       * @param filter
       * @param pageSubscription
       * @param durable
       * @param temporary
       * @param scheduledExecutor
       * @param postOffice
       * @param storageManager
       * @param addressSettingsRepository
       * @param executor
       */
      public MyQueueWithBlocking(
          final long id,
          final SimpleString address,
          final SimpleString name,
          final Filter filter,
          final PageSubscription pageSubscription,
          final boolean durable,
          final boolean temporary,
          final ScheduledExecutorService scheduledExecutor,
          final PostOffice postOffice,
          final StorageManager storageManager,
          final HierarchicalRepository<AddressSettings> addressSettingsRepository,
          final Executor executor) {
        super(
            id,
            address,
            name,
            filter,
            pageSubscription,
            durable,
            temporary,
            scheduledExecutor,
            postOffice,
            storageManager,
            addressSettingsRepository,
            executor);
      }

      @Override
      public synchronized int deleteMatchingReferences(final int flushLimit, final Filter filter)
          throws Exception {
        latchDelete.countDown();
        blocked.acquire();
        blocked.release();
        return super.deleteMatchingReferences(flushLimit, filter);
      }
    }

    class LocalFactory extends QueueFactoryImpl {
      public LocalFactory(
          final ExecutorFactory executorFactory,
          final ScheduledExecutorService scheduledExecutor,
          final HierarchicalRepository<AddressSettings> addressSettingsRepository,
          final StorageManager storageManager) {
        super(executorFactory, scheduledExecutor, addressSettingsRepository, storageManager);
      }

      @Override
      public Queue createQueue(
          final long persistenceID,
          final SimpleString address,
          final SimpleString name,
          final Filter filter,
          final PageSubscription pageSubscription,
          final boolean durable,
          final boolean temporary) {
        queue =
            new MyQueueWithBlocking(
                persistenceID,
                address,
                name,
                filter,
                pageSubscription,
                durable,
                temporary,
                scheduledExecutor,
                postOffice,
                storageManager,
                addressSettingsRepository,
                executorFactory.getExecutor());
        return queue;
      }
    }

    LocalFactory queueFactory =
        new LocalFactory(
            server.getExecutorFactory(),
            server.getScheduledPool(),
            server.getAddressSettingsRepository(),
            server.getStorageManager());

    queueFactory.setPostOffice(server.getPostOffice());

    ((HornetQServerImpl) server).replaceQueueFactory(queueFactory);

    queue = server.createQueue(QUEUE, QUEUE, null, true, false);

    blocked.acquire();

    ClientSessionFactory factory = locator.createSessionFactory();
    ClientSession session = factory.createSession(false, false, false);

    ClientProducer producer = session.createProducer(QUEUE);

    producer.send(session.createMessage(true));
    session.commit();

    Thread tDelete =
        new Thread() {
          @Override
          public void run() {
            try {
              server.destroyQueue(QUEUE);
            } catch (Exception e) {
              e.printStackTrace();
            }
          }
        };

    tDelete.start();

    Assert.assertTrue(latchDelete.await(10, TimeUnit.SECONDS));

    try {
      server.createQueue(QUEUE, QUEUE, null, true, false);
    } catch (Exception expected) {
    }

    blocked.release();

    server.stop();

    tDelete.join();

    session.close();

    // a duplicate binding would impede the server from starting
    server.start();
    waitForServer(server);

    server.stop();
  }