activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Clebert Suconic <clebert.suco...@gmail.com>
Subject Re: delete messages from artemis broker
Date Wed, 25 Oct 2017 15:25:08 GMT
You could do it per queue...

What we do in our own testsuite.. is to stop the server and start the
server on each test.. and use small journal files.. so it starts
really fast.

There's even artemis-junit, that you could embed in your tests.. and
that would do that work for you.


Look into our test... EmbeddedJMSREsourceQueueTest.. which is testing
the EmbeddedJMSResource.


If you really want to keep the same external server running (i.e you
are running integration tests against the real server), then  you
could call removeMessages on each Queue.



If ActiveMQ had a deleteAllMessages method and you really want it, we
could have a simple implementation there as well. Would you liked to
send a PR?

On Wed, Oct 25, 2017 at 9:05 AM, preben <preben.asmussen@gmail.com> wrote:
> Im switching from Activemq to Artemis and have to migrate some unittests
>
> I got a activemq baseclass like ->
>
>  @Before
>     public void startEmbeddedBroker() throws Exception {
>         broker = new BrokerService();
>         TransportConnector connector =
> broker.addConnector("tcp://localhost:61616");
>         broker.setPersistent(false);
>         broker.setUseJmx(true);
>         broker.deleteAllMessages();
>         broker.start();
>         broker.waitUntilStarted();
>         ActiveMQConnectionFactory connFactory = new
> ActiveMQConnectionFactory(connector.getConnectUri() +
> "?jms.prefetchPolicy.all=1");
>         connection = connFactory.createConnection();
>         connection.start();
>     }
>
>     @After
>     public void stopEmbeddedBroker() throws Exception {
>         // wait a bit to let client connections get act's before shutdown
>         Thread.sleep(2000);
>         connection.stop();
>         broker.stop();
>     }
>
> That work well for activemq.
> The artemis test baseclass is refactored to ->
>
> @Before
>     public void startEmbeddedBroker() throws Exception {
>         FileUtils.deleteQuietly(new File("target/data"));
>         broker = new EmbeddedJMS();
>         brokerUri = "tcp://localhost:61616";
>         configureBroker(this.broker);
>         startBroker();
>     }
>
>     protected void configureBroker(EmbeddedJMS broker) throws Exception {
>         Configuration configuration = new ConfigurationImpl()
>             .setPersistenceEnabled(false)
>             .setJournalDirectory("target/data/journal")
>             .setSecurityEnabled(false)
>             .addAcceptorConfiguration("connector", brokerUri +
> "?protocols=CORE")
>             .addConnectorConfiguration("connector", new
> TransportConfiguration(NettyConnectorFactory.class.getName()));
>
>         JMSConfiguration jmsConfig = new JMSConfigurationImpl();
>
>         ConnectionFactoryConfiguration cfConfig = new
> ConnectionFactoryConfigurationImpl()
>             .setName("cf").setConnectorNames(Arrays.asList("connector"))
>             .setBindings("cf");
>         jmsConfig.getConnectionFactoryConfigurations().add(cfConfig);
>
>
> broker.setConfiguration(configuration).setJmsConfiguration(jmsConfig);
>     }
>
>     private void startBroker() throws Exception {
>         broker.start();
>     }
>
>     @After
>     public void stopEmbeddedBroker() throws Exception {
>         broker.stop();
>         broker = null;
>     }
>
> The only thing missing is the ability to purge all queus and topics like the
> one for activemq =  *broker.deleteAllMessages()*;
>
> Without that it seems like the tests will see messages enqued in previous
> test (if in same test class) ??
>
> How can I purge all messages in Artemis.
>
> /preben
>
>
>
>
>
> --
> Sent from: http://activemq.2283324.n4.nabble.com/ActiveMQ-User-f2341805.html



-- 
Clebert Suconic

Mime
View raw message