use of org.apache.activemq.artemis.api.core.ActiveMQBuffer in project activemq-artemis by apache.
the class TransportConfigurationEncodingSupportTest method testTransportConfigurations.
@Test
public void testTransportConfigurations() throws Exception {
List<Pair<TransportConfiguration, TransportConfiguration>> connectorConfigs = new ArrayList<>();
Map<String, Object> liveParams = new HashMap<>();
liveParams.put(TransportConstants.PORT_PROP_NAME, 5665);
TransportConfiguration live1 = new TransportConfiguration(NettyConnectorFactory.class.getName(), liveParams);
Map<String, Object> backupParams = new HashMap<>();
backupParams.put(TransportConstants.PORT_PROP_NAME, 5775);
TransportConfiguration backup1 = new TransportConfiguration(NettyConnectorFactory.class.getName(), backupParams);
Map<String, Object> liveParams2 = new HashMap<>();
liveParams2.put(TransportConstants.PORT_PROP_NAME, 6665);
TransportConfiguration live2 = new TransportConfiguration(NettyConnectorFactory.class.getName(), liveParams2);
connectorConfigs.add(new Pair<>(live1, backup1));
connectorConfigs.add(new Pair<TransportConfiguration, TransportConfiguration>(live2, null));
ActiveMQBuffer buffer = ActiveMQBuffers.fixedBuffer(TransportConfigurationEncodingSupport.getEncodeSize(connectorConfigs));
TransportConfigurationEncodingSupport.encodeConfigs(buffer, connectorConfigs);
assertEquals(buffer.capacity(), buffer.writerIndex());
buffer.readerIndex(0);
List<Pair<TransportConfiguration, TransportConfiguration>> decodedConfigs = TransportConfigurationEncodingSupport.decodeConfigs(buffer);
assertNotNull(decodedConfigs);
assertEquals(2, decodedConfigs.size());
assertEquivalent(connectorConfigs.get(0).getA(), decodedConfigs.get(0).getA());
assertEquivalent(connectorConfigs.get(0).getB(), decodedConfigs.get(0).getB());
assertEquivalent(connectorConfigs.get(1).getA(), decodedConfigs.get(1).getA());
assertNull(decodedConfigs.get(1).getB());
}
use of org.apache.activemq.artemis.api.core.ActiveMQBuffer in project activemq-artemis by apache.
the class JournalPageCountSizeTest method testPageCountRecordSize.
@Test
public void testPageCountRecordSize() throws Exception {
long tx = server.getStorageManager().generateID();
server.getStorageManager().storePageCounter(tx, 1, 1, 100);
server.getStorageManager().commit(tx);
server.getStorageManager().stop();
JournalStorageManager journalStorageManager = (JournalStorageManager) server.getStorageManager();
List<RecordInfo> committedRecords = new LinkedList<>();
List<PreparedTransactionInfo> preparedTransactions = new LinkedList<>();
try {
journalStorageManager.getMessageJournal().start();
journalStorageManager.getMessageJournal().load(committedRecords, preparedTransactions, transactionFailure);
ActiveMQBuffer buff = ActiveMQBuffers.wrappedBuffer(committedRecords.get(0).data);
PageCountRecord encoding = new PageCountRecord();
encoding.decode(buff);
Assert.assertEquals(100, encoding.getPersistentSize());
} finally {
journalStorageManager.getMessageJournal().stop();
}
}
use of org.apache.activemq.artemis.api.core.ActiveMQBuffer in project activemq-artemis by apache.
the class JournalPageCountSizeTest method testPageCursorCounterRecordSize.
@Test
public void testPageCursorCounterRecordSize() throws Exception {
server.getStorageManager().storePageCounterInc(1, 1, 1000);
server.getStorageManager().stop();
JournalStorageManager journalStorageManager = (JournalStorageManager) server.getStorageManager();
List<RecordInfo> committedRecords = new LinkedList<>();
List<PreparedTransactionInfo> preparedTransactions = new LinkedList<>();
try {
journalStorageManager.getMessageJournal().start();
journalStorageManager.getMessageJournal().load(committedRecords, preparedTransactions, transactionFailure);
ActiveMQBuffer buff = ActiveMQBuffers.wrappedBuffer(committedRecords.get(0).data);
PageCountRecordInc encoding = new PageCountRecordInc();
encoding.decode(buff);
Assert.assertEquals(1000, encoding.getPersistentSize());
} finally {
journalStorageManager.getMessageJournal().stop();
}
}
use of org.apache.activemq.artemis.api.core.ActiveMQBuffer in project activemq-artemis by apache.
the class PagingSyncTest method testOrder1.
@Test
public void testOrder1() throws Throwable {
boolean persistentMessages = true;
Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false);
ActiveMQServer server = createServer(true, config, PAGE_SIZE, PAGE_MAX, new HashMap<String, AddressSettings>());
server.start();
final int messageSize = 1024;
final int numberOfMessages = 500;
ServerLocator locator = createInVMNonHALocator().setClientFailureCheckPeriod(1000).setConnectionTTL(2000).setReconnectAttempts(0).setBlockOnNonDurableSend(false).setBlockOnDurableSend(false).setBlockOnAcknowledge(false).setConsumerWindowSize(1024 * 1024);
ClientSessionFactory sf = createSessionFactory(locator);
ClientSession session = sf.createSession(false, false, false);
server.addAddressInfo(new AddressInfo(ADDRESS, RoutingType.ANYCAST));
server.createQueue(ADDRESS, RoutingType.ANYCAST, ADDRESS, null, true, false);
ClientProducer producer = session.createProducer(PagingTest.ADDRESS);
byte[] body = new byte[messageSize];
ByteBuffer bb = ByteBuffer.wrap(body);
for (int j = 1; j <= messageSize; j++) {
bb.put(getSamplebyte(j));
}
for (int i = 0; i < numberOfMessages; i++) {
ClientMessage message = session.createMessage(persistentMessages);
ActiveMQBuffer bodyLocal = message.getBodyBuffer();
bodyLocal.writeBytes(body);
message.putIntProperty(new SimpleString("id"), i);
producer.send(message);
}
session.commit();
session.close();
}
use of org.apache.activemq.artemis.api.core.ActiveMQBuffer in project activemq-artemis by apache.
the class PagingOrderTest method testPageCounter2.
@Test
public void testPageCounter2() throws Throwable {
boolean persistentMessages = true;
Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false);
ActiveMQServer server = createServer(true, config, PAGE_SIZE, PAGE_MAX, new HashMap<String, AddressSettings>());
server.start();
final int messageSize = 1024;
final int numberOfMessages = 500;
ServerLocator locator = createInVMNonHALocator().setClientFailureCheckPeriod(1000).setConnectionTTL(2000).setReconnectAttempts(0).setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true).setConsumerWindowSize(1024 * 1024);
ClientSessionFactory sf = createSessionFactory(locator);
ClientSession session = sf.createSession(false, false, false);
server.addAddressInfo(new AddressInfo(ADDRESS, RoutingType.ANYCAST));
Queue q1 = server.createQueue(ADDRESS, RoutingType.MULTICAST, ADDRESS, null, true, false);
Queue q2 = server.createQueue(ADDRESS, RoutingType.MULTICAST, new SimpleString("inactive"), null, true, false);
ClientProducer producer = session.createProducer(PagingTest.ADDRESS);
byte[] body = new byte[messageSize];
ByteBuffer bb = ByteBuffer.wrap(body);
for (int j = 1; j <= messageSize; j++) {
bb.put(getSamplebyte(j));
}
final AtomicInteger errors = new AtomicInteger(0);
Thread t1 = new Thread() {
@Override
public void run() {
try {
ServerLocator sl = createInVMNonHALocator();
ClientSessionFactory sf = sl.createSessionFactory();
ClientSession sess = sf.createSession(true, true, 0);
sess.start();
ClientConsumer cons = sess.createConsumer(ADDRESS);
for (int i = 0; i < 100; i++) {
ClientMessage msg = cons.receive(5000);
assertNotNull(msg);
assertEquals(i, msg.getIntProperty("id").intValue());
msg.acknowledge();
}
sess.close();
sl.close();
} catch (Throwable e) {
e.printStackTrace();
errors.incrementAndGet();
}
}
};
for (int i = 0; i < numberOfMessages; i++) {
ClientMessage message = session.createMessage(persistentMessages);
ActiveMQBuffer bodyLocal = message.getBodyBuffer();
bodyLocal.writeBytes(body);
message.putIntProperty(new SimpleString("id"), i);
producer.send(message);
if (i % 20 == 0) {
session.commit();
}
}
session.commit();
t1.start();
t1.join();
assertEquals(0, errors.get());
long timeout = System.currentTimeMillis() + 10000;
while (numberOfMessages - 100 != getMessageCount(q1) && System.currentTimeMillis() < timeout) {
Thread.sleep(500);
}
assertEquals(numberOfMessages, getMessageCount(q2));
assertEquals(numberOfMessages, getMessagesAdded(q2));
assertEquals(numberOfMessages - 100, getMessageCount(q1));
}
Aggregations