public void testStateChanged() {
   notifyBrokerStarted();
   UUID id = UUID.randomUUID();
   ConfiguredObject object = mock(VirtualHost.class);
   when(object.isDurable()).thenReturn(true);
   when(object.getId()).thenReturn(id);
   ConfiguredObjectRecord record = mock(ConfiguredObjectRecord.class);
   when(object.asObjectRecord()).thenReturn(record);
   _listener.stateChanged(object, State.ACTIVE, State.DELETED);
   verify(_store).remove(record);
 }
Example #2
0
 @Override
 public State call() {
   return _object.setDesiredState(_expectedState, _desiredState);
 }
  @Override
  protected void doOpen(final ConfiguredObject<?> parent) throws StoreException {
    JDBCSettings settings = (JDBCSettings) parent;
    _connectionURL = settings.getConnectionUrl();

    JDBCDetails details = JDBCDetails.getDetailsForJdbcUrl(_connectionURL, parent);

    if (!details.isKnownVendor() && getLogger().isInfoEnabled()) {
      getLogger()
          .info(
              "Do not recognize vendor from connection URL: "
                  + _connectionURL
                  + " Using fallback settings "
                  + details);
    }
    if (details.isOverridden() && getLogger().isInfoEnabled()) {
      getLogger()
          .info(
              "One or more JDBC details were overridden from context. "
                  + " Using settings : "
                  + details);
    }

    _blobType = details.getBlobType();
    _varBinaryType = details.getVarBinaryType();
    _useBytesMethodsForBlob = details.isUseBytesMethodsForBlob();
    _bigIntType = details.getBigintType();

    String connectionPoolType =
        settings.getConnectionPoolType() == null
            ? DefaultConnectionProviderFactory.TYPE
            : settings.getConnectionPoolType();

    JDBCConnectionProviderFactory connectionProviderFactory =
        JDBCConnectionProviderFactory.FACTORIES.get(connectionPoolType);
    if (connectionProviderFactory == null) {
      _logger.warn(
          "Unknown connection pool type: "
              + connectionPoolType
              + ".  No connection pooling will be used");
      connectionProviderFactory = new DefaultConnectionProviderFactory();
    }

    try {
      Map<String, String> providerAttributes = new HashMap<>();
      Set<String> providerAttributeNames =
          new HashSet<String>(connectionProviderFactory.getProviderAttributeNames());
      providerAttributeNames.retainAll(parent.getContextKeys(false));
      for (String attr : providerAttributeNames) {
        providerAttributes.put(attr, parent.getContextValue(String.class, attr));
      }

      _connectionProvider =
          connectionProviderFactory.getConnectionProvider(
              _connectionURL,
              settings.getUsername(),
              getPlainTextPassword(settings),
              providerAttributes);
    } catch (SQLException e) {
      throw new StoreException(
          "Failed to create connection provider for connectionUrl: "
              + _connectionURL
              + " and username: "
              + settings.getUsername());
    }
  }