use of org.apache.activemq.artemis.core.postoffice.PostOffice in project activemq-artemis by apache.
the class ClusterTestBase method waitForMessages.
protected void waitForMessages(final int node, final String address, final int count) throws Exception {
ActiveMQServer server = servers[node];
if (server == null) {
throw new IllegalArgumentException("No server at " + node);
}
PostOffice po = server.getPostOffice();
long start = System.currentTimeMillis();
int messageCount = 0;
do {
messageCount = getMessageCount(po, address);
if (messageCount == count) {
return;
}
Thread.sleep(10);
} while (System.currentTimeMillis() - start < ActiveMQTestBase.WAIT_TIMEOUT);
throw new IllegalStateException("Timed out waiting for messages (messageCount = " + messageCount + ", expecting = " + count);
}
use of org.apache.activemq.artemis.core.postoffice.PostOffice in project activemq-artemis by apache.
the class ClusterTestBase method debugBindings.
protected String debugBindings(final ActiveMQServer server, final String address) throws Exception {
StringWriter str = new StringWriter();
PrintWriter out = new PrintWriter(str);
if (server == null) {
return "server is shutdown";
}
PostOffice po = server.getPostOffice();
if (po == null) {
return "server is shutdown";
}
Bindings bindings = po.getBindingsForAddress(new SimpleString(address));
out.println("=======================================================================");
out.println("Binding information for address = " + address + " on " + server);
for (Binding binding : bindings.getBindings()) {
QueueBinding qBinding = (QueueBinding) binding;
out.println("Binding = " + qBinding + ", queue=" + qBinding.getQueue());
}
out.println("=======================================================================");
return str.toString();
}
use of org.apache.activemq.artemis.core.postoffice.PostOffice in project activemq-artemis by apache.
the class ActiveMQTestBase method printBindings.
public void printBindings(ActiveMQServer server, String address) throws Exception {
PostOffice po = server.getPostOffice();
Bindings bindings = po.getBindingsForAddress(new SimpleString(address));
System.err.println("=======================================================================");
System.err.println("Binding information for address = " + address + " for server " + server);
for (Binding binding : bindings.getBindings()) {
QueueBinding qBinding = (QueueBinding) binding;
System.err.println("Binding = " + qBinding + ", queue=" + qBinding.getQueue());
}
}
use of org.apache.activemq.artemis.core.postoffice.PostOffice in project activemq-artemis by apache.
the class ActiveMQTestBase method waitForBindings.
/**
* @param server the server where's being checked
* @param address the name of the address being checked
* @param local if true we are looking for local bindings, false we are looking for remoting servers
* @param expectedBindingCount the expected number of counts
* @param expectedConsumerCount the expected number of consumers
* @param timeout the timeout used on the check
* @return
* @throws Exception
* @throws InterruptedException
*/
protected boolean waitForBindings(final ActiveMQServer server, final String address, final boolean local, final int expectedBindingCount, final int expectedConsumerCount, long timeout) throws Exception {
final PostOffice po = server.getPostOffice();
long start = System.currentTimeMillis();
int bindingCount = 0;
int totConsumers = 0;
do {
bindingCount = 0;
totConsumers = 0;
Bindings bindings = po.getBindingsForAddress(new SimpleString(address));
for (Binding binding : bindings.getBindings()) {
if (binding.isConnected() && (binding instanceof LocalQueueBinding && local || binding instanceof RemoteQueueBinding && !local)) {
QueueBinding qBinding = (QueueBinding) binding;
bindingCount++;
totConsumers += qBinding.consumerCount();
}
}
if (bindingCount == expectedBindingCount && totConsumers == expectedConsumerCount) {
return true;
}
Thread.sleep(10);
} while (System.currentTimeMillis() - start < timeout);
String msg = "Timed out waiting for bindings (bindingCount = " + bindingCount + " (expecting " + expectedBindingCount + ") " + ", totConsumers = " + totConsumers + " (expecting " + expectedConsumerCount + ")" + ")";
log.error(msg);
return false;
}
use of org.apache.activemq.artemis.core.postoffice.PostOffice in project activemq-artemis by apache.
the class DuplicateDetectionUnitTest method testReloadDuplication.
// Public --------------------------------------------------------
@Test
public void testReloadDuplication() throws Exception {
JournalStorageManager journal = null;
try {
clearDataRecreateServerDirs();
SimpleString ADDRESS = new SimpleString("address");
Configuration configuration = createDefaultInVMConfig();
PostOffice postOffice = new FakePostOffice();
ScheduledExecutorService scheduledThreadPool = Executors.newScheduledThreadPool(ActiveMQDefaultConfiguration.getDefaultScheduledThreadPoolMaxSize(), ActiveMQThreadFactory.defaultThreadFactory());
journal = new JournalStorageManager(configuration, EmptyCriticalAnalyzer.getInstance(), factory, factory);
journal.start();
journal.loadBindingJournal(new ArrayList<QueueBindingInfo>(), new ArrayList<GroupingInfo>(), new ArrayList<AddressBindingInfo>());
HashMap<SimpleString, List<Pair<byte[], Long>>> mapDups = new HashMap<>();
FakePagingManager pagingManager = new FakePagingManager();
journal.loadMessageJournal(postOffice, pagingManager, new ResourceManagerImpl(0, 0, scheduledThreadPool), null, mapDups, null, null, new PostOfficeJournalLoader(postOffice, pagingManager, null, null, null, null, null, null));
Assert.assertEquals(0, mapDups.size());
DuplicateIDCacheImpl cacheID = new DuplicateIDCacheImpl(ADDRESS, 10, journal, true);
for (int i = 0; i < 100; i++) {
cacheID.addToCache(RandomUtil.randomBytes());
}
journal.stop();
journal = new JournalStorageManager(configuration, EmptyCriticalAnalyzer.getInstance(), factory, factory);
journal.start();
journal.loadBindingJournal(new ArrayList<QueueBindingInfo>(), new ArrayList<GroupingInfo>(), new ArrayList<AddressBindingInfo>());
journal.loadMessageJournal(postOffice, pagingManager, new ResourceManagerImpl(0, 0, scheduledThreadPool), null, mapDups, null, null, new PostOfficeJournalLoader(postOffice, pagingManager, null, null, null, null, null, null));
Assert.assertEquals(1, mapDups.size());
List<Pair<byte[], Long>> values = mapDups.get(ADDRESS);
Assert.assertEquals(10, values.size());
cacheID = new DuplicateIDCacheImpl(ADDRESS, 10, journal, true);
cacheID.load(values);
for (int i = 0; i < 100; i++) {
cacheID.addToCache(RandomUtil.randomBytes(), null);
}
journal.stop();
mapDups.clear();
journal = new JournalStorageManager(configuration, EmptyCriticalAnalyzer.getInstance(), factory, factory);
journal.start();
journal.loadBindingJournal(new ArrayList<QueueBindingInfo>(), new ArrayList<GroupingInfo>(), new ArrayList<AddressBindingInfo>());
journal.loadMessageJournal(postOffice, pagingManager, new ResourceManagerImpl(0, 0, scheduledThreadPool), null, mapDups, null, null, new PostOfficeJournalLoader(postOffice, pagingManager, null, null, null, null, null, null));
Assert.assertEquals(1, mapDups.size());
values = mapDups.get(ADDRESS);
Assert.assertEquals(10, values.size());
scheduledThreadPool.shutdown();
} finally {
if (journal != null) {
try {
journal.stop();
} catch (Throwable ignored) {
}
}
}
}
Aggregations