Java Code Examples for org.apache.activemq.store.jdbc.JDBCPersistenceAdapter#setDataSource()

The following examples show how to use org.apache.activemq.store.jdbc.JDBCPersistenceAdapter#setDataSource() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JdbcXARecoveryBrokerTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected void configureBroker(BrokerService broker) throws Exception {
   super.configureBroker(broker);

   JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter();
   jdbc.setDataSource(dataSource);
   broker.setPersistenceAdapter(jdbc);
}
 
Example 2
Source File: JDBCQueueMasterSlaveTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected void createMaster() throws Exception {
   master = new BrokerService();
   master.setBrokerName("master");
   master.addConnector(MASTER_URL);
   master.setUseJmx(false);
   master.setPersistent(true);
   master.setDeleteAllMessagesOnStartup(true);
   JDBCPersistenceAdapter persistenceAdapter = new JDBCPersistenceAdapter();
   persistenceAdapter.setDataSource(getExistingDataSource());
   configureJdbcPersistenceAdapter(persistenceAdapter);
   master.setPersistenceAdapter(persistenceAdapter);
   configureBroker(master);
   master.start();
}
 
Example 3
Source File: JDBCQueueMasterSlaveTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected void createSlave() throws Exception {
   // use a separate thread as the slave will block waiting for
   // the exclusive db lock
   Thread t = new Thread() {
      @Override
      public void run() {
         try {
            BrokerService broker = new BrokerService();
            broker.setBrokerName("slave");
            TransportConnector connector = new TransportConnector();
            connector.setUri(new URI(SLAVE_URL));
            broker.addConnector(connector);
            // no need for broker.setMasterConnectorURI(masterConnectorURI)
            // as the db lock provides the slave/master initialisation
            broker.setUseJmx(false);
            broker.setPersistent(true);
            JDBCPersistenceAdapter persistenceAdapter = new JDBCPersistenceAdapter();
            persistenceAdapter.setDataSource(getExistingDataSource());
            persistenceAdapter.setCreateTablesOnStartup(false);
            broker.setPersistenceAdapter(persistenceAdapter);
            configureJdbcPersistenceAdapter(persistenceAdapter);
            configureBroker(broker);
            broker.start();
            slave.set(broker);
            slaveStarted.countDown();
         } catch (IllegalStateException expectedOnShutdown) {
         } catch (Exception e) {
            fail("failed to start slave broker, reason:" + e);
         }
      }
   };
   t.start();
}
 
Example 4
Source File: DbRestartJDBCQueueTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
   setAutoFail(true);
   topic = false;
   verbose = true;
   // startup db
   sharedDs = (EmbeddedDataSource) DataSourceServiceSupport.createDataSource(IOHelper.getDefaultDataDirectory());

   broker = new BrokerService();

   DefaultIOExceptionHandler handler = new DefaultIOExceptionHandler();
   handler.setIgnoreSQLExceptions(false);
   handler.setStopStartConnectors(true);
   broker.setIoExceptionHandler(handler);
   broker.addConnector("tcp://localhost:0");
   broker.setUseJmx(false);
   broker.setPersistent(true);
   broker.setDeleteAllMessagesOnStartup(true);
   JDBCPersistenceAdapter persistenceAdapter = new JDBCPersistenceAdapter();
   persistenceAdapter.setDataSource(sharedDs);
   persistenceAdapter.setUseLock(false);
   persistenceAdapter.setLockKeepAlivePeriod(500);
   persistenceAdapter.getLocker().setLockAcquireSleepInterval(500);
   broker.setPersistenceAdapter(persistenceAdapter);
   broker.start();
   super.setUp();
}
 
Example 5
Source File: ConfigTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testJdbcLockConfigOverride() throws Exception {

   JDBCPersistenceAdapter adapter = new JDBCPersistenceAdapter();
   Mockery context = new Mockery();
   final DataSource dataSource = context.mock(DataSource.class);
   final Connection connection = context.mock(Connection.class);
   final DatabaseMetaData metadata = context.mock(DatabaseMetaData.class);
   final ResultSet result = context.mock(ResultSet.class);
   adapter.setDataSource(dataSource);
   adapter.setCreateTablesOnStartup(false);

   context.checking(new Expectations() {{
      allowing(dataSource).getConnection();
      will(returnValue(connection));
      allowing(connection).getMetaData();
      will(returnValue(metadata));
      allowing(connection);
      allowing(metadata).getDriverName();
      will(returnValue("Microsoft_SQL_Server_2005_jdbc_driver"));
      allowing(result).next();
      will(returnValue(true));
   }});

   adapter.start();
   assertTrue("has the locker override", adapter.getLocker() instanceof TransactDatabaseLocker);
   adapter.stop();
}
 
Example 6
Source File: ConfigTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public void testJdbcLockConfigDefault() throws Exception {

      JDBCPersistenceAdapter adapter = new JDBCPersistenceAdapter();
      Mockery context = new Mockery();
      final DataSource dataSource = context.mock(DataSource.class);
      final Connection connection = context.mock(Connection.class);
      final DatabaseMetaData metadata = context.mock(DatabaseMetaData.class);
      final ResultSet result = context.mock(ResultSet.class);
      adapter.setDataSource(dataSource);
      adapter.setCreateTablesOnStartup(false);

      context.checking(new Expectations() {{
         allowing(dataSource).getConnection();
         will(returnValue(connection));
         allowing(connection).getMetaData();
         will(returnValue(metadata));
         allowing(connection);
         allowing(metadata).getDriverName();
         will(returnValue("Some_Unknown_driver"));
         allowing(result).next();
         will(returnValue(true));
      }});

      adapter.start();
      assertEquals("has the default locker", adapter.getLocker().getClass(), DefaultDatabaseLocker.class);
      adapter.stop();
   }
 
Example 7
Source File: JDBCDurableSubscriptionTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected PersistenceAdapter createPersistenceAdapter() throws IOException {
   JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter();
   EmbeddedDataSource dataSource = new EmbeddedDataSource();
   dataSource.setDatabaseName("derbyDb");
   dataSource.setCreateDatabase("create");
   jdbc.setDataSource(dataSource);
   jdbc.setCleanupPeriod(1000); // set up small cleanup period
   return jdbc;
}