@Override
  public void setUp() throws Exception {
    super.setUp();

    SystemConfig systemConfig = mock(SystemConfig.class);
    when(systemConfig.getEventLogger()).thenReturn(mock(EventLogger.class));
    Broker<?> broker = mock(Broker.class);
    when(broker.getParent(SystemConfig.class)).thenReturn(systemConfig);
    when(broker.getModel()).thenReturn(BrokerModel.getInstance());
    when(broker.getSecurityManager()).thenReturn(new SecurityManager(broker, false));

    _taskExecutor = new TaskExecutorImpl();
    _taskExecutor.start();
    when(broker.getTaskExecutor()).thenReturn(_taskExecutor);
    when(broker.getChildExecutor()).thenReturn(_taskExecutor);

    _node = mock(VirtualHostNode.class);
    when(_node.getParent(Broker.class)).thenReturn(broker);
    when(_node.getModel()).thenReturn(BrokerModel.getInstance());
    when(_node.getTaskExecutor()).thenReturn(_taskExecutor);
    when(_node.getChildExecutor()).thenReturn(_taskExecutor);
    when(_node.getConfigurationStore()).thenReturn(mock(DurableConfigurationStore.class));
    when(_node.getCategoryClass()).thenReturn(VirtualHostNode.class);

    _failingStore = mock(MessageStore.class);
    doThrow(new RuntimeException("Cannot open store"))
        .when(_failingStore)
        .openMessageStore(any(ConfiguredObject.class));
  }
Example #2
0
  private void cleanUp(int exitStatusCode) {
    _taskExecutor.stop();

    if (_shutdownAction != null) {
      _shutdownAction.performAction(exitStatusCode);
    }

    _systemConfig = null;
  }
 @Override
 public void tearDown() throws Exception {
   try {
     if (_taskExecutor != null) {
       _taskExecutor.stop();
     }
   } finally {
     super.tearDown();
   }
 }
Example #4
0
  private void startupImpl(final BrokerOptions options) throws Exception {
    populateSystemPropertiesFromDefaults(options.getInitialSystemProperties());

    String storeType = options.getConfigurationStoreType();

    // Create the RootLogger to be used during broker operation
    boolean statusUpdatesEnabled =
        Boolean.parseBoolean(System.getProperty(BrokerProperties.PROPERTY_STATUS_UPDATES, "true"));
    MessageLogger messageLogger = new LoggingMessageLogger(statusUpdatesEnabled);
    _eventLogger.setMessageLogger(messageLogger);

    PluggableFactoryLoader<SystemConfigFactory> configFactoryLoader =
        new PluggableFactoryLoader<>(SystemConfigFactory.class);
    SystemConfigFactory configFactory = configFactoryLoader.get(storeType);
    if (configFactory == null) {
      LOGGER.error(
          "Unknown config store type '"
              + storeType
              + "', only the following types are supported: "
              + configFactoryLoader.getSupportedTypes());
      throw new IllegalArgumentException(
          "Unknown config store type '"
              + storeType
              + "', only the following types are supported: "
              + configFactoryLoader.getSupportedTypes());
    }

    _taskExecutor.start();
    _systemConfig =
        configFactory.newInstance(
            _taskExecutor, _eventLogger, options.convertToSystemConfigAttributes());
    _systemConfig.open();
    if (_systemConfig.getBroker().getState() == State.ERRORED) {
      throw new RuntimeException("Closing broker as it cannot operate due to errors");
    }
  }