I’m using Apache ActiveMQ for testing JMS based code. With their Springframework support it’s pretty simple to embed it into a test suite. Today I encountered a strange problem. After I had broken my test and fixed the bug later I was not able to restart the embedded ActiveMQ container.

Obviously java.io.EOFException: Chunk stream does not exist at page: 0 sounds like some temporary file data was corrupt. JobSchedulerStore creates a directory activemq-data/localhost/scheduler for storing scheduler data. Clean/delete that and it should be startable again. If you don’t need that then you are better off with completely deactivating that feature.

1
2
3
4
5
  <amq:broker useJmx="true" persistent="false" start="false" schedulerSupport="true">
      <amq:transportConnectors>
          <amq:transportConnector uri="${amq.brokerURL}" />
      </amq:transportConnectors>
  </amq:broker>

Also its helpful to disable automatic start of the queue container so the test can fully control it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
public class ServiceOperationsJmsProducerTest extends AbstractJUnit4SpringContextTests implements BrokerServiceAware {
  private BrokerService brokerService;

  @Test
  public void testProducer() throws Exception {
      try {
          brokerService.start();
          // do the testing
      } finally {
          brokerService.stop();
          brokerService.waitUntilStopped();
      }
  }

  @Override
  @Resource
  public void setBrokerService(BrokerService brokerService) {
      this.brokerService = brokerService;
  }
}

Comments