org.apache.activemq.store.PersistenceAdapter Java Examples

The following examples show how to use org.apache.activemq.store.PersistenceAdapter. 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: ActiveMQ5Factory.java    From tomee with Apache License 2.0 6 votes vote down vote up
private static PersistenceAdapter createPersistenceAdapter(final String clazz, final String prefix, final Map<String, String> params) throws IllegalAccessException, InvocationTargetException, ClassNotFoundException, InstantiationException {
    Class<?> aClass = Thread.currentThread().getContextClassLoader().loadClass(clazz);
    final PersistenceAdapter persistenceAdapter = PersistenceAdapter.class.cast(aClass.newInstance());
    while (aClass != null) {
        for (final Method m : aClass.getDeclaredMethods()) {
            if (m.getName().startsWith("set") && m.getParameterTypes().length == 1 && Modifier.isPublic(m.getModifiers())) {
                final String key = prefix + "." + m.getName().substring(3).toLowerCase(Locale.ENGLISH);
                final Object field = params.remove(key);
                if (field != null) {
                    try {
                        final Object toSet = propertyEditorRegistry.getValue(m.getParameterTypes()[0], field.toString());
                        m.invoke(persistenceAdapter, toSet);
                    } catch (final PropertyEditorException cantConvertException) {
                        throw new IllegalArgumentException("can't convert " + field + " for " + m.getName(), cantConvertException);
                    }
                }
            }
        }
        aClass = aClass.getSuperclass();
    }
    return persistenceAdapter;
}
 
Example #2
Source File: ConfigTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testJournalConfig() throws Exception {
   File journalFile = new File(JOURNAL_ROOT + "testJournalConfig/journal");
   recursiveDelete(journalFile);

   BrokerService broker;
   broker = createBroker(new FileSystemResource(CONF_ROOT + "journal-example.xml"));
   try {
      assertEquals("Broker Config Error (brokerName)", "brokerJournalConfigTest", broker.getBrokerName());

      PersistenceAdapter adapter = broker.getPersistenceAdapter();

      assertTrue("Should have created a journal persistence adapter", adapter instanceof JournalPersistenceAdapter);
      assertTrue("Should have created a journal directory at " + journalFile.getAbsolutePath(), journalFile.exists());

      LOG.info("Success");
   } finally {
      if (broker != null) {
         broker.stop();
      }
   }
}
 
Example #3
Source File: CassandraStepdefs.java    From james-project with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws Exception {
    cassandraServer.start();
    temporaryFolder.create();
    elasticSearch.start();

    mainStepdefs.messageIdFactory = new CassandraMessageId.Factory();
    Configuration configuration = Configuration.builder()
        .workingDirectory(temporaryFolder.newFolder())
        .configurationFromClasspath()
        .build();

    mainStepdefs.jmapServer = CassandraJamesServerMain.createServer(configuration)
        .overrideWith(new TestJMAPServerModule())
        .overrideWith(new TestDockerESMetricReporterModule(elasticSearch.getDockerEs().getHttpHost()))
        .overrideWith(elasticSearch.getModule())
        .overrideWith(cassandraServer.getModule())
        .overrideWith(binder -> binder.bind(TextExtractor.class).to(DefaultTextExtractor.class))
        .overrideWith((binder) -> binder.bind(PersistenceAdapter.class).to(MemoryPersistenceAdapter.class))
        .overrideWith(binder -> Multibinder.newSetBinder(binder, CleanupTasksPerformer.CleanupTask.class).addBinding().to(CassandraTruncateTableTask.class))
        .overrideWith((binder -> binder.bind(CleanupTasksPerformer.class).asEagerSingleton()));
    mainStepdefs.awaitMethod = () -> elasticSearch.getDockerEs().flushIndices();
    mainStepdefs.init();
}
 
Example #4
Source File: CheckDuplicateMessagesOnDuplexTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private void createLocalBroker() throws Exception {
   localBroker = new BrokerService();
   localBroker.setBrokerName("LOCAL");
   localBroker.setUseJmx(true);
   localBroker.setSchedulePeriodForDestinationPurge(5000);
   ManagementContext managementContext = new ManagementContext();
   managementContext.setCreateConnector(false);
   localBroker.setManagementContext(managementContext);
   PersistenceAdapter persistenceAdapter = persistenceAdapterFactory("target/local");
   localBroker.setPersistenceAdapter(persistenceAdapter);
   List<TransportConnector> transportConnectors = new ArrayList<>();
   DebugTransportFactory tf = new DebugTransportFactory();
   TransportServer transport = tf.doBind(URI.create("nio://127.0.0.1:23539"));
   TransportConnector transportConnector = new TransportConnector(transport);
   transportConnector.setName("tc");
   transportConnector.setAuditNetworkProducers(true);
   transportConnectors.add(transportConnector);
   localBroker.setTransportConnectors(transportConnectors);
}
 
Example #5
Source File: CheckDuplicateMessagesOnDuplexTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private void createRemoteBroker() throws Exception {
   remoteBroker = new BrokerService();
   remoteBroker.setBrokerName("REMOTE");
   remoteBroker.setUseJmx(true);
   remoteBroker.setSchedulePeriodForDestinationPurge(5000);
   ManagementContext managementContext = new ManagementContext();
   managementContext.setCreateConnector(false);
   remoteBroker.setManagementContext(managementContext);
   PersistenceAdapter persistenceAdapter = persistenceAdapterFactory("target/remote");
   remoteBroker.setPersistenceAdapter(persistenceAdapter);
   List<NetworkConnector> networkConnectors = new ArrayList<>();
   DiscoveryNetworkConnector networkConnector = new DiscoveryNetworkConnector();
   networkConnector.setName("to local");
   // set maxInactivityDuration to 0, otherwise the broker restarts while you are in the debugger
   networkConnector.setUri(URI.create("static://(tcp://127.0.0.1:23539?wireFormat.maxInactivityDuration=0)"));
   networkConnector.setDuplex(true);
   //networkConnector.setNetworkTTL(5);
   //networkConnector.setDynamicOnly(true);
   networkConnector.setAlwaysSyncSend(true);
   networkConnector.setDecreaseNetworkConsumerPriority(false);
   networkConnector.setPrefetchSize(1);
   networkConnector.setCheckDuplicateMessagesOnDuplex(true);
   networkConnectors.add(networkConnector);
   remoteBroker.setNetworkConnectors(networkConnectors);
}
 
Example #6
Source File: RecoverExpiredMessagesTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public void initCombosForTestRecovery() throws Exception {
   addCombinationValues("queuePendingPolicy", new PendingQueueMessageStoragePolicy[]{new FilePendingQueueMessageStoragePolicy(), new VMPendingQueueMessageStoragePolicy()});
   PersistenceAdapter[] persistenceAdapters = new PersistenceAdapter[]{new KahaDBPersistenceAdapter(), new JDBCPersistenceAdapter(DataSourceServiceSupport.createDataSource(IOHelper.getDefaultDataDirectory()), new OpenWireFormat())};
   for (PersistenceAdapter adapter : persistenceAdapters) {
      adapter.setDirectory(new File(IOHelper.getDefaultDataDirectory()));
   }
   addCombinationValues("persistenceAdapter", persistenceAdapters);
}
 
Example #7
Source File: ActivemqConfiguration.java    From onetwo with Apache License 2.0 5 votes vote down vote up
@Bean
public PersistenceAdapter kahaDBPersistenceAdapter(){
	KahaDBStoreProps kahaProps = activemqProperties.getKahadbStore();
	// default messages store is under AMQ_HOME/data/KahaDB/
	KahaDBPersistenceAdapter kahadb = new KahaDBPersistenceAdapter();
	if(StringUtils.isNotBlank(kahaProps.getDataDir())){
		File dataDir = new File(kahaProps.getDataDir());
		if(!dataDir.exists()){
			dataDir.mkdirs();
		}
		kahadb.setDirectory(dataDir);
	}
	return kahadb;
}
 
Example #8
Source File: ConfigTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testJournaledJDBCConfig() throws Exception {

   File journalFile = new File(JOURNAL_ROOT + "testJournaledJDBCConfig/journal");
   recursiveDelete(journalFile);

   File derbyFile = new File(DERBY_ROOT + "testJournaledJDBCConfig/derbydb"); // Default
   recursiveDelete(derbyFile);

   BrokerService broker;
   broker = createBroker(new FileSystemResource(CONF_ROOT + "journaledjdbc-example.xml"));
   try {
      assertEquals("Broker Config Error (brokerName)", "brokerJournaledJDBCConfigTest", broker.getBrokerName());

      PersistenceAdapter adapter = broker.getPersistenceAdapter();

      assertTrue("Should have created a journal persistence adapter", adapter instanceof JournalPersistenceAdapter);
      assertTrue("Should have created a derby directory at " + derbyFile.getAbsolutePath(), derbyFile.exists());
      assertTrue("Should have created a journal directory at " + journalFile.getAbsolutePath(), journalFile.exists());

      // Check persistence factory configurations
      broker.getPersistenceAdapter();

      assertTrue(broker.getSystemUsage().getStoreUsage().getStore() instanceof JournalPersistenceAdapter);

      LOG.info("Success");
   } finally {
      if (broker != null) {
         broker.stop();
      }
   }
}
 
Example #9
Source File: ConfigTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testMemoryConfig() throws Exception {
   File journalFile = new File(JOURNAL_ROOT + "testMemoryConfig");
   recursiveDelete(journalFile);

   File derbyFile = new File(DERBY_ROOT + "testMemoryConfig");
   recursiveDelete(derbyFile);

   BrokerService broker;
   broker = createBroker(new FileSystemResource(CONF_ROOT + "memory-example.xml"));

   try {
      assertEquals("Broker Config Error (brokerName)", "brokerMemoryConfigTest", broker.getBrokerName());

      PersistenceAdapter adapter = broker.getPersistenceAdapter();

      assertTrue("Should have created a memory persistence adapter", adapter instanceof MemoryPersistenceAdapter);
      assertTrue("Should have not created a derby directory at " + derbyFile.getAbsolutePath(), !derbyFile.exists());
      assertTrue("Should have not created a journal directory at " + journalFile.getAbsolutePath(), !journalFile.exists());

      LOG.info("Success");
   } finally {
      if (broker != null) {
         broker.stop();
      }
   }
}
 
Example #10
Source File: JDBCConfigTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testJdbcConfig() throws Exception {
   File journalFile = new File(JOURNAL_ROOT + "testJDBCConfig/journal");
   recursiveDelete(journalFile);

   File derbyFile = new File(DERBY_ROOT + "testJDBCConfig/derbydb"); // Default
   recursiveDelete(derbyFile);

   BrokerService broker;
   broker = createBroker(new FileSystemResource(CONF_ROOT + "jdbc-example.xml"));
   try {
      assertEquals("Broker Config Error (brokerName)", "brokerJdbcConfigTest", broker.getBrokerName());

      PersistenceAdapter adapter = broker.getPersistenceAdapter();

      assertTrue("Should have created a jdbc persistence adapter", adapter instanceof JDBCPersistenceAdapter);
      assertEquals("JDBC Adapter Config Error (cleanupPeriod)", 60000, ((JDBCPersistenceAdapter) adapter).getCleanupPeriod());
      assertTrue("Should have created an EmbeddedDataSource", ((JDBCPersistenceAdapter) adapter).getDataSource() instanceof EmbeddedDataSource);
      assertTrue("Should have created a DefaultWireFormat", ((JDBCPersistenceAdapter) adapter).getWireFormat() instanceof ObjectStreamWireFormat);

      LOG.info("Success");
   } finally {
      if (broker != null) {
         broker.stop();
      }
   }
}
 
Example #11
Source File: JournalDurableSubscriptionTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected PersistenceAdapter createPersistenceAdapter() throws IOException {
   File dataDir = new File("target/test-data/durableJournal");
   JournalPersistenceAdapterFactory factory = new JournalPersistenceAdapterFactory();
   factory.setDataDirectoryFile(dataDir);
   factory.setUseJournal(true);
   factory.setJournalLogFileSize(1024 * 64);
   return factory.createPersistenceAdapter();
}
 
Example #12
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;
}
 
Example #13
Source File: LevelDBDurableSubscriptionTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected PersistenceAdapter createPersistenceAdapter() throws IOException {
   File dataDir = new File("target/test-data/durableLevelDB");
   LevelDBStore adaptor = new LevelDBStore();
   adaptor.setDirectory(dataDir);
   return adaptor;
}
 
Example #14
Source File: TemporaryJamesServer.java    From james-project with Apache License 2.0 5 votes vote down vote up
private TemporaryJamesServer(File workingDir, MailetContainer mailetContainer, SmtpConfiguration smtpConfiguration,
                             Module serverBaseModule, List<Module> additionalModules) throws Exception {
    appendMailetConfigurations(workingDir, mailetContainer);
    appendSmtpConfigurations(workingDir, smtpConfiguration);

    Configuration configuration = Configuration.builder().workingDirectory(workingDir).build();
    copyResources(Paths.get(workingDir.getAbsolutePath(), "conf"));

    jamesServer = GuiceJamesServer.forConfiguration(configuration)
        .combineWith(serverBaseModule)
        .overrideWith((binder) -> binder.bind(PersistenceAdapter.class).to(MemoryPersistenceAdapter.class))
        .overrideWith(additionalModules)
        .overrideWith(new TestJMAPServerModule())
        .overrideWith((binder) -> binder.bind(WebAdminConfiguration.class).toInstance(WebAdminConfiguration.TEST_CONFIGURATION));
}
 
Example #15
Source File: RabbitMQAwsS3Stepdefs.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Before
public void init() throws Exception {
    cassandraServer.start();
    rabbitMQServer.start();
    swiftServer.start();
    elasticSearch.start();

    temporaryFolder.create();
    mainStepdefs.messageIdFactory = new CassandraMessageId.Factory();
    CassandraRabbitMQJamesConfiguration configuration = CassandraRabbitMQJamesConfiguration.builder()
        .workingDirectory(temporaryFolder.newFolder())
        .configurationFromClasspath()
        .blobStore(BlobStoreConfiguration.objectStorage().disableCache())
        .build();

    mainStepdefs.jmapServer = CassandraRabbitMQJamesServerMain.createServer(configuration)
        .overrideWith(new TestJMAPServerModule())
            .overrideWith(new TestDockerESMetricReporterModule(elasticSearch.getDockerEs().getHttpHost()))
            .overrideWith(new TestRabbitMQModule(rabbitMQServer.dockerRabbitMQ()))
            .overrideWith(swiftServer.getModule())
            .overrideWith(elasticSearch.getModule())
            .overrideWith(cassandraServer.getModule())
            .overrideWith(binder -> binder.bind(TextExtractor.class).to(DefaultTextExtractor.class))
            .overrideWith((binder) -> binder.bind(PersistenceAdapter.class).to(MemoryPersistenceAdapter.class))
            .overrideWith(binder -> Multibinder.newSetBinder(binder, CleanupTasksPerformer.CleanupTask.class).addBinding().to(CassandraTruncateTableTask.class))
            .overrideWith((binder -> binder.bind(CleanupTasksPerformer.class).asEagerSingleton()));
    mainStepdefs.awaitMethod = () -> elasticSearch.getDockerEs().flushIndices();
    mainStepdefs.init();
}
 
Example #16
Source File: EmbeddedActiveMQ.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Inject
private EmbeddedActiveMQ(FileSystem fileSystem, PersistenceAdapter persistenceAdapter) {
    this.persistenceAdapter = persistenceAdapter;
    try {
        persistenceAdapter.setDirectory(fileSystem.getFile(KAHADB_STORE_LOCATION));
        launchEmbeddedBroker(fileSystem);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    activeMQConnectionFactory = createActiveMQConnectionFactory(createBlobTransferPolicy(fileSystem));
}
 
Example #17
Source File: OpenEjbBrokerFactoryTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
public void testNoDataSource() throws Exception {
    final BrokerService broker = BrokerFactory.createBroker(new URI(getBrokerUri(
        "broker:(tcp://localhost:" + brokerPort + ")?useJmx=false")));
    assertNotNull("broker is null", broker);

    final PersistenceAdapter persistenceAdapter = broker.getPersistenceAdapter();
    assertNotNull("persistenceAdapter is null", persistenceAdapter);

    assertTrue("persistenceAdapter should be an instance of MemoryPersistenceAdapter",
        persistenceAdapter instanceof MemoryPersistenceAdapter);

    stopBroker(broker);
}
 
Example #18
Source File: OpenEjbBrokerFactoryTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
public void testDirectDataSource() throws Exception {

        final Properties properties = new Properties();

        final JDBCDataSource dataSource = new JDBCDataSource();
        dataSource.setDatabase("jdbc:hsqldb:mem:testdb" + System.currentTimeMillis());
        dataSource.setUser("sa");
        dataSource.setPassword("");
        dataSource.getConnection().close();

        properties.put("DataSource", dataSource);
        properties.put("UseDatabaseLock", "false");
        properties.put("StartupTimeout", "10000");

        ActiveMQFactory.setThreadProperties(properties);
        BrokerService broker = null;
        try {
            broker = BrokerFactory.createBroker(new URI(getBrokerUri(
                "broker:(tcp://localhost:" + brokerPort + ")?useJmx=false")));
            assertNotNull("broker is null", broker);

            final PersistenceAdapter persistenceAdapter = broker.getPersistenceAdapter();
            assertNotNull("persistenceAdapter is null", persistenceAdapter);

            assertTrue("persistenceAdapter should be an instance of JDBCPersistenceAdapter",
                persistenceAdapter instanceof JDBCPersistenceAdapter);
            final JDBCPersistenceAdapter jdbcPersistenceAdapter = (JDBCPersistenceAdapter) persistenceAdapter;

            assertSame(dataSource, jdbcPersistenceAdapter.getDataSource());
        } finally {
            stopBroker(broker);
            ActiveMQFactory.setThreadProperties(null);
        }
    }
 
Example #19
Source File: StoreQueueCursorKahaDBNoDuplicateTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected BrokerService createBroker() throws Exception {
   BrokerService broker = super.createBroker();
   PersistenceAdapter persistenceAdapter = new KahaDBStore();
   persistenceAdapter.setDirectory(new File("target/activemq-data/kahadb"));
   broker.setPersistenceAdapter(persistenceAdapter);
   return broker;
}
 
Example #20
Source File: ActivemqConfiguration.java    From onetwo with Apache License 2.0 5 votes vote down vote up
@ConditionalOnMissingBean
@Bean(initMethod="start", destroyMethod="stop")
public BrokerService brokerService(PersistenceAdapter persistenceAdapter) throws IOException{
	BrokerService broker = new BrokerService();
	broker.setPersistenceAdapter(persistenceAdapter);
	return broker;
}
 
Example #21
Source File: ActivemqConfiguration.java    From onetwo with Apache License 2.0 5 votes vote down vote up
@Bean
public PersistenceAdapter jdbcPersistenceAdapter(DataSource dataSource){
	JdbcStoreProps jdbcProps = activemqProperties.getJdbcStore();
	JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter(dataSource, new OpenWireFormat());
	jdbc.setCreateTablesOnStartup(jdbcProps.isCreateTablesOnStartup());
	return jdbc;
}
 
Example #22
Source File: SystemUsage.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public SystemUsage(String name,
                   PersistenceAdapter adapter,
                   PListStore tempStore,
                   JobSchedulerStore jobSchedulerStore) {
   this.parent = null;
   this.name = name;
   this.memoryUsage = new MemoryUsage(name + ":memory");
   this.storeUsage = new StoreUsage(name + ":store", adapter);
   this.tempUsage = new TempUsage(name + ":temp", tempStore);
   this.jobSchedulerUsage = new JobSchedulerUsage(name + ":jobScheduler", jobSchedulerStore);
   this.memoryUsage.setExecutor(getExecutor());
   this.storeUsage.setExecutor(getExecutor());
   this.tempUsage.setExecutor(getExecutor());
}
 
Example #23
Source File: CheckDuplicateMessagesOnDuplexTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private PersistenceAdapter persistenceAdapterFactory_KahaDB(String path) {
   KahaDBPersistenceAdapter kahaDBPersistenceAdapter = new KahaDBPersistenceAdapter();
   kahaDBPersistenceAdapter.setDirectory(new File(path));
   kahaDBPersistenceAdapter.setIgnoreMissingJournalfiles(true);
   kahaDBPersistenceAdapter.setCheckForCorruptJournalFiles(true);
   kahaDBPersistenceAdapter.setChecksumJournalFiles(true);
   return kahaDBPersistenceAdapter;
}
 
Example #24
Source File: CheckDuplicateMessagesOnDuplexTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private PersistenceAdapter persistenceAdapterFactory(String path) {
   if (useLevelDB) {
      return persistenceAdapterFactory_LevelDB(path);
   } else {
      return persistenceAdapterFactory_KahaDB(path);
   }
}
 
Example #25
Source File: StoreQueueCursorJDBCNoDuplicateTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected BrokerService createBroker() throws Exception {
   BrokerService broker = super.createBroker();
   PersistenceAdapter persistenceAdapter = new JDBCPersistenceAdapter();
   broker.setPersistenceAdapter(persistenceAdapter);
   return broker;
}
 
Example #26
Source File: MQTTNetworkOfBrokersFailoverTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected BrokerService createRemoteBroker(PersistenceAdapter persistenceAdapter) throws Exception {
   BrokerService broker = super.createRemoteBroker(persistenceAdapter);
   broker.setPersistent(true);
   broker.setDeleteAllMessagesOnStartup(true);
   broker.setDataDirectory("target/activemq-data");
   TransportConnector tc = broker.addConnector(getDefaultMQTTTransportConnectorUri());
   remoteBrokerMQTTPort = tc.getConnectUri().getPort();
   return broker;
}
 
Example #27
Source File: NetworkTestSupport.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected BrokerService createRemoteBroker(PersistenceAdapter persistenceAdapter) throws Exception {
   BrokerService answer = new BrokerService();
   answer.setBrokerName("remote");
   answer.setUseJmx(useJmx);
   answer.setPersistenceAdapter(persistenceAdapter);
   return answer;
}
 
Example #28
Source File: LevelDBStoreBrokerTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected PersistenceAdapter createPersistenceAdapter(boolean delete) {
   LevelDBStore store = new LevelDBStore();
   store.setDirectory(new File("target/activemq-data/leveldb"));
   if (delete) {
      store.deleteAllMessages();
   }
   return store;
}
 
Example #29
Source File: KahaDBDurableSubscriptionTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Override
protected PersistenceAdapter createPersistenceAdapter() throws IOException {
   return null; // use default
}
 
Example #30
Source File: OpenEjbBrokerFactoryTest.java    From tomee with Apache License 2.0 4 votes vote down vote up
public void testLookupDataSource() throws Exception {

        final Properties properties = new Properties();

        final JDBCDataSource dataSource = new JDBCDataSource();
        dataSource.setDatabase("jdbc:hsqldb:mem:testdb" + System.currentTimeMillis());
        dataSource.setUser("sa");
        dataSource.setPassword("");
        dataSource.getConnection().close();

        MockInitialContextFactory.install(Collections.singletonMap("openejb/Resource/TestDs", dataSource));
        assertSame(dataSource, new InitialContext().lookup("openejb/Resource/TestDs"));

        final CoreContainerSystem containerSystem = new CoreContainerSystem(new IvmJndiFactory());
        containerSystem.getJNDIContext().bind("openejb/Resource/TestDs", dataSource);
        SystemInstance.get().setComponent(ContainerSystem.class, containerSystem);

        properties.put("DataSource", "TestDs");
        properties.put("UseDatabaseLock", "false");
        properties.put("StartupTimeout", "10000");

        ActiveMQFactory.setThreadProperties(properties);
        BrokerService broker = null;
        try {
            broker = BrokerFactory.createBroker(new URI(getBrokerUri(
                "broker:(tcp://localhost:" + brokerPort + ")?useJmx=false")));
            assertNotNull("broker is null", broker);

            final PersistenceAdapter persistenceAdapter = broker.getPersistenceAdapter();
            assertNotNull("persistenceAdapter is null", persistenceAdapter);

            assertTrue("persistenceAdapter should be an instance of JDBCPersistenceAdapter",
                persistenceAdapter instanceof JDBCPersistenceAdapter);
            final JDBCPersistenceAdapter jdbcPersistenceAdapter = (JDBCPersistenceAdapter) persistenceAdapter;

            assertSame(dataSource, jdbcPersistenceAdapter.getDataSource());
        } finally {
            stopBroker(broker);
            ActiveMQFactory.setThreadProperties(null);
        }
    }