public void testStartInErrorStateAfterOpen() throws Exception {
    Map<String, Object> attributes =
        Collections.<String, Object>singletonMap(AbstractVirtualHost.NAME, getTestName());
    final MessageStore store = mock(MessageStore.class);
    doThrow(new RuntimeException("Cannot open store"))
        .when(store)
        .openMessageStore(any(ConfiguredObject.class));
    AbstractVirtualHost host =
        new AbstractVirtualHost(attributes, _node) {
          @Override
          protected MessageStore createMessageStore() {
            return store;
          }
        };

    host.open();
    assertEquals("Unexpected state", State.ERRORED, host.getState());

    doNothing().when(store).openMessageStore(any(ConfiguredObject.class));
    when(store.newMessageStoreReader()).thenReturn(mock(MessageStore.MessageStoreReader.class));

    host.start();
    assertEquals("Unexpected state", State.ACTIVE, host.getState());
    host.close();
  }
  // This indirectly tests QPID-6283
  public void testFileSystemCheckWarnsWhenFileSystemDoesNotExist() throws Exception {
    Map<String, Object> attributes =
        Collections.<String, Object>singletonMap(AbstractVirtualHost.NAME, getTestName());
    final MessageStore store = mock(MessageStore.class);
    when(store.newMessageStoreReader()).thenReturn(mock(MessageStore.MessageStoreReader.class));
    File nonExistingFile = TestFileUtils.createTempFile(this);
    FileUtils.delete(nonExistingFile, false);
    when(store.getStoreLocationAsFile()).thenReturn(nonExistingFile);
    setTestSystemProperty("virtualhost.housekeepingCheckPeriod", "100");

    final AbstractVirtualHost host =
        new AbstractVirtualHost(attributes, _node) {
          @Override
          protected MessageStore createMessageStore() {
            return store;
          }
        };

    String loggerName = AbstractVirtualHost.class.getName();
    assertActionProducesLogMessage(
        new Runnable() {
          @Override
          public void run() {
            host.open();
          }
        },
        loggerName,
        Level.WARN,
        "Cannot check file system for disk space");
    host.close();
  }
  public void testOpenSucceeds() {
    Map<String, Object> attributes =
        Collections.<String, Object>singletonMap(AbstractVirtualHost.NAME, getTestName());
    final MessageStore store = mock(MessageStore.class);
    when(store.newMessageStoreReader()).thenReturn(mock(MessageStore.MessageStoreReader.class));

    AbstractVirtualHost host =
        new AbstractVirtualHost(attributes, _node) {
          @Override
          protected MessageStore createMessageStore() {
            return store;
          }
        };

    host.open();
    assertEquals("Unexpected host state", State.ACTIVE, host.getState());
    verify(store).openMessageStore(host);

    // make sure that method AbstractVirtualHost.onExceptionInOpen was not called
    verify(store, times(0)).closeMessageStore();
    host.close();
  }