use of org.apache.activemq.artemis.core.persistence.StorageManager in project activemq-artemis by apache.
the class ReplicationTest method testNoActions.
@Test
public void testNoActions() throws Exception {
setupServer(true);
StorageManager storage = getStorage();
manager = liveServer.getReplicationManager();
waitForComponent(manager);
Journal replicatedJournal = new ReplicatedJournal((byte) 1, new FakeJournal(), manager);
replicatedJournal.appendPrepareRecord(1, new FakeData(), false);
final CountDownLatch latch = new CountDownLatch(1);
storage.afterCompleteOperations(new IOCallback() {
@Override
public void onError(final int errorCode, final String errorMessage) {
}
@Override
public void done() {
latch.countDown();
}
});
Assert.assertTrue(latch.await(1, TimeUnit.SECONDS));
Assert.assertEquals("should be empty " + manager.getActiveTokens(), 0, manager.getActiveTokens().size());
}
use of org.apache.activemq.artemis.core.persistence.StorageManager in project activemq-artemis by apache.
the class ReplicationTest method testOrderOnNonPersistency.
@Test
public void testOrderOnNonPersistency() throws Exception {
setupServer(true);
final ArrayList<Integer> executions = new ArrayList<>();
StorageManager storage = getStorage();
manager = liveServer.getReplicationManager();
Journal replicatedJournal = new ReplicatedJournal((byte) 1, new FakeJournal(), manager);
int numberOfAdds = 200;
final CountDownLatch latch = new CountDownLatch(numberOfAdds);
OperationContext ctx = storage.getContext();
for (int i = 0; i < numberOfAdds; i++) {
final int nAdd = i;
if (i % 2 == 0) {
replicatedJournal.appendPrepareRecord(i, new FakeData(), false);
}
ctx.executeOnCompletion(new IOCallback() {
@Override
public void onError(final int errorCode, final String errorMessage) {
}
@Override
public void done() {
executions.add(nAdd);
latch.countDown();
}
});
}
Assert.assertTrue(latch.await(10, TimeUnit.SECONDS));
for (int i = 0; i < numberOfAdds; i++) {
Assert.assertEquals(i, executions.get(i).intValue());
}
Assert.assertEquals(0, manager.getActiveTokens().size());
}
use of org.apache.activemq.artemis.core.persistence.StorageManager in project activemq-artemis by apache.
the class PageCursorStressTest method testConsumeLivePageMultiThread.
@Test
public void testConsumeLivePageMultiThread() throws Exception {
final PagingStoreImpl pageStore = lookupPageStore(ADDRESS);
pageStore.startPaging();
final int NUM_TX = 100;
final int MSGS_TX = 100;
final int TOTAL_MSG = NUM_TX * MSGS_TX;
final int messageSize = 1024;
PageCursorProvider cursorProvider = this.server.getPagingManager().getPageStore(ADDRESS).getCursorProvider();
System.out.println("cursorProvider = " + cursorProvider);
PageSubscription cursor = this.server.getPagingManager().getPageStore(ADDRESS).getCursorProvider().getSubscription(queue.getID());
System.out.println("Cursor: " + cursor);
final StorageManager storage = this.server.getStorageManager();
final AtomicInteger exceptions = new AtomicInteger(0);
Thread t1 = new Thread() {
@Override
public void run() {
try {
int count = 0;
for (int txCount = 0; txCount < NUM_TX; txCount++) {
Transaction tx = null;
if (txCount % 2 == 0) {
tx = new TransactionImpl(storage);
}
RoutingContext ctx = generateCTX(tx);
for (int i = 0; i < MSGS_TX; i++) {
// System.out.println("Sending " + count);
ActiveMQBuffer buffer = RandomUtil.randomBuffer(messageSize, count);
Message msg = new CoreMessage(i, buffer.writerIndex());
msg.putIntProperty("key", count++);
msg.getBodyBuffer().writeBytes(buffer, 0, buffer.writerIndex());
Assert.assertTrue(pageStore.page(msg, ctx.getTransaction(), ctx.getContextListing(ADDRESS), lock));
}
if (tx != null) {
tx.commit();
}
}
} catch (Throwable e) {
e.printStackTrace();
exceptions.incrementAndGet();
}
}
};
t1.start();
LinkedListIterator<PagedReference> iterator = cursor.iterator();
for (int i = 0; i < TOTAL_MSG; i++) {
assertEquals(0, exceptions.get());
PagedReference ref = null;
for (int repeat = 0; repeat < 5; repeat++) {
ref = iterator.next();
if (ref == null) {
Thread.sleep(1000);
} else {
break;
}
}
assertNotNull(ref);
ref.acknowledge();
assertNotNull(ref);
System.out.println("Consuming " + ref.getMessage().getIntProperty("key"));
// assertEquals(i, ref.getMessage().getIntProperty("key").intValue());
}
assertEquals(0, exceptions.get());
}
use of org.apache.activemq.artemis.core.persistence.StorageManager in project activemq-artemis by apache.
the class PagingCounterTest method testCleanupCounter.
@Test
public void testCleanupCounter() throws Exception {
ClientSessionFactory sf = createSessionFactory(sl);
ClientSession session = sf.createSession();
try {
server.addAddressInfo(new AddressInfo(new SimpleString("A1"), RoutingType.ANYCAST));
Queue queue = server.createQueue(new SimpleString("A1"), RoutingType.ANYCAST, new SimpleString("A1"), null, true, false);
PageSubscriptionCounter counter = locateCounter(queue);
StorageManager storage = server.getStorageManager();
Transaction tx = new TransactionImpl(server.getStorageManager());
for (int i = 0; i < 2100; i++) {
counter.increment(tx, 1, 1000);
if (i % 200 == 0) {
tx.commit();
storage.waitOnOperations();
assertEquals(i + 1, counter.getValue());
assertEquals((i + 1) * 1000, counter.getPersistentSize());
tx = new TransactionImpl(server.getStorageManager());
}
}
tx.commit();
storage.waitOnOperations();
assertEquals(2100, counter.getValue());
assertEquals(2100 * 1000, counter.getPersistentSize());
server.stop();
server = newActiveMQServer();
server.start();
queue = server.locateQueue(new SimpleString("A1"));
assertNotNull(queue);
counter = locateCounter(queue);
assertEquals(2100, counter.getValue());
assertEquals(2100 * 1000, counter.getPersistentSize());
} finally {
sf.close();
session.close();
}
}
use of org.apache.activemq.artemis.core.persistence.StorageManager in project activemq-artemis by apache.
the class PagingCounterTest method testRestartCounter.
@Test
public void testRestartCounter() throws Exception {
server.addAddressInfo(new AddressInfo(new SimpleString("A1"), RoutingType.ANYCAST));
Queue queue = server.createQueue(new SimpleString("A1"), RoutingType.ANYCAST, new SimpleString("A1"), null, true, false);
PageSubscriptionCounter counter = locateCounter(queue);
StorageManager storage = server.getStorageManager();
Transaction tx = new TransactionImpl(server.getStorageManager());
counter.increment(tx, 1, 1000);
assertEquals(0, counter.getValue());
assertEquals(0, counter.getPersistentSize());
tx.commit();
storage.waitOnOperations();
assertEquals(1, counter.getValue());
assertEquals(1000, counter.getPersistentSize());
sl.close();
server.stop();
server = newActiveMQServer();
server.start();
queue = server.locateQueue(new SimpleString("A1"));
assertNotNull(queue);
counter = locateCounter(queue);
assertEquals(1, counter.getValue());
assertEquals(1000, counter.getPersistentSize());
}
Aggregations