use of org.apache.activemq.artemis.api.core.Message in project activemq-artemis by apache.
the class LargeMessageCompressTest method testLargeMessageCompression2.
@Test
public void testLargeMessageCompression2() throws Exception {
final int messageSize = (int) (3.5 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE);
ActiveMQServer server = createServer(true, isNetty());
server.start();
ClientSessionFactory sf = createSessionFactory(locator);
ClientSession session = addClientSession(sf.createSession(false, false, false));
session.createTemporaryQueue(ADDRESS, ADDRESS);
ClientProducer producer = session.createProducer(ADDRESS);
Message clientFile = createLargeClientMessageStreaming(session, messageSize, true);
producer.send(clientFile);
session.commit();
session.start();
ClientConsumer consumer = session.createConsumer(ADDRESS);
ClientMessage msg1 = consumer.receive(1000);
Assert.assertNotNull(msg1);
String testDir = getTestDir();
File testFile = new File(testDir, "async_large_message");
FileOutputStream output = new FileOutputStream(testFile);
msg1.setOutputStream(output);
msg1.waitOutputStreamCompletion(0);
msg1.acknowledge();
output.close();
session.commit();
consumer.close();
session.close();
// verify
FileInputStream input = new FileInputStream(testFile);
for (int i = 0; i < messageSize; i++) {
byte b = (byte) input.read();
assertEquals("position = " + i, getSamplebyte(i), b);
}
input.close();
testFile.delete();
validateNoFilesOnLargeDir();
}
use of org.apache.activemq.artemis.api.core.Message in project activemq-artemis by apache.
the class LargeMessageCompressTest method testLargeMessageCompressionRestartAndCheckSize.
@Test
public void testLargeMessageCompressionRestartAndCheckSize() throws Exception {
final int messageSize = 1024 * 1024;
ActiveMQServer server = createServer(true, isNetty());
server.start();
ClientSessionFactory sf = createSessionFactory(locator);
ClientSession session = addClientSession(sf.createSession(false, false, false));
session.createQueue(ADDRESS, ADDRESS, true);
ClientProducer producer = session.createProducer(ADDRESS);
byte[] msgs = new byte[1024 * 1024];
for (int i = 0; i < msgs.length; i++) {
msgs[i] = RandomUtil.randomByte();
}
Message clientFile = createLargeClientMessage(session, msgs, true);
producer.send(clientFile);
session.commit();
session.close();
sf.close();
locator.close();
server.stop();
server = createServer(true, isNetty());
server.start();
locator = createFactory(isNetty());
sf = createSessionFactory(locator);
session = sf.createSession();
session.start();
ClientConsumer consumer = session.createConsumer(ADDRESS);
ClientMessage msg1 = consumer.receive(1000);
Assert.assertNotNull(msg1);
assertEquals(messageSize, msg1.getBodySize());
String testDir = getTestDir();
File testFile = new File(testDir, "async_large_message");
FileOutputStream output = new FileOutputStream(testFile);
msg1.saveToOutputStream(output);
msg1.acknowledge();
session.commit();
consumer.close();
session.close();
// verify
FileInputStream input = new FileInputStream(testFile);
for (int i = 0; i < messageSize; i++) {
byte b = (byte) input.read();
assertEquals("position = " + i, msgs[i], b);
}
input.close();
testFile.delete();
validateNoFilesOnLargeDir();
}
use of org.apache.activemq.artemis.api.core.Message in project activemq-artemis by apache.
the class SendAckFailTest method testSend.
@Test
public void testSend() throws Exception {
Process process = SpawnedVMSupport.spawnVM(SendAckFailTest.class.getName());
ActiveMQServer server = null;
try {
HashSet<Integer> listSent = new HashSet<>();
Thread t = null;
{
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory();
ServerLocator locator = factory.getServerLocator();
locator.setConfirmationWindowSize(0).setInitialConnectAttempts(100).setRetryInterval(100).setBlockOnDurableSend(false).setReconnectAttempts(0);
ClientSessionFactory sf = locator.createSessionFactory();
ClientSession session = sf.createSession();
session.createAddress(SimpleString.toSimpleString("T1"), RoutingType.ANYCAST, true);
session.createQueue(SimpleString.toSimpleString("T1"), RoutingType.ANYCAST, SimpleString.toSimpleString("T1"), true);
ClientProducer producer = session.createProducer("T1");
session.setSendAcknowledgementHandler(new SendAcknowledgementHandler() {
@Override
public void sendAcknowledged(Message message) {
listSent.add(message.getIntProperty("myid"));
}
});
t = new Thread() {
@Override
public void run() {
for (int i = 0; i < 5000; i++) {
try {
producer.send(session.createMessage(true).putIntProperty("myid", i));
} catch (Exception e) {
e.printStackTrace();
break;
}
}
}
};
t.start();
}
Wait.waitFor(() -> listSent.size() > 100, 5000, 10);
Assert.assertTrue(process.waitFor(1, TimeUnit.MINUTES));
server = startServer(false);
{
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory();
ServerLocator locator = factory.getServerLocator();
ClientSessionFactory sf = locator.createSessionFactory();
ClientSession session = sf.createSession();
ClientConsumer consumer = session.createConsumer("T1");
session.start();
for (int i = 0; i < listSent.size(); i++) {
ClientMessage message = consumer.receive(1000);
if (message == null) {
for (Integer msgi : listSent) {
System.out.println("Message " + msgi + " was lost");
}
fail("missed messages!");
}
message.acknowledge();
if (!listSent.remove(message.getIntProperty("myid"))) {
System.out.println("Message " + message + " with id " + message.getIntProperty("myid") + " received in duplicate");
fail("Message " + message + " with id " + message.getIntProperty("myid") + " received in duplicate");
}
}
}
} finally {
if (process != null) {
process.destroy();
}
if (server != null) {
server.stop();
}
}
}
use of org.apache.activemq.artemis.api.core.Message in project activemq-artemis by apache.
the class QueueImplTest method testGetFilter.
@Test
public void testGetFilter() {
QueueImpl queue = getTemporaryQueue();
Assert.assertNull(queue.getFilter());
Filter filter = new Filter() {
@Override
public boolean match(final Message message) {
return false;
}
@Override
public SimpleString getFilterString() {
return null;
}
};
queue = getFilteredQueue(filter);
Assert.assertEquals(filter, queue.getFilter());
}
use of org.apache.activemq.artemis.api.core.Message in project activemq-artemis by apache.
the class PagingStoreImplTest method testDepageOnCurrentPage.
@Test
public void testDepageOnCurrentPage() throws Exception {
SequentialFileFactory factory = new FakeSequentialFileFactory();
SimpleString destination = new SimpleString("test");
PagingStoreFactory storeFactory = new FakeStoreFactory(factory);
PagingStoreImpl storeImpl = new PagingStoreImpl(PagingStoreImplTest.destinationTestName, null, 100, createMockManager(), createStorageManagerMock(), factory, storeFactory, PagingStoreImplTest.destinationTestName, new AddressSettings().setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE), getExecutorFactory().getExecutor(), true);
storeImpl.start();
Assert.assertEquals(0, storeImpl.getNumberOfPages());
storeImpl.startPaging();
List<ActiveMQBuffer> buffers = new ArrayList<>();
int numMessages = 10;
for (int i = 0; i < numMessages; i++) {
ActiveMQBuffer buffer = createRandomBuffer(i + 1L, 10);
buffers.add(buffer);
Message msg = createMessage(i, storeImpl, destination, buffer);
final RoutingContextImpl ctx = new RoutingContextImpl(null);
Assert.assertTrue(storeImpl.page(msg, ctx.getTransaction(), ctx.getContextListing(storeImpl.getStoreName()), lock));
}
Assert.assertEquals(1, storeImpl.getNumberOfPages());
storeImpl.sync();
Page page = storeImpl.depage();
page.open();
List<PagedMessage> msg = page.read(new NullStorageManager());
Assert.assertEquals(numMessages, msg.size());
Assert.assertEquals(1, storeImpl.getNumberOfPages());
page = storeImpl.depage();
Assert.assertNull(page);
Assert.assertEquals(0, storeImpl.getNumberOfPages());
for (int i = 0; i < numMessages; i++) {
ActiveMQBuffer horn1 = buffers.get(i);
ActiveMQBuffer horn2 = msg.get(i).getMessage().toCore().getBodyBuffer();
horn1.resetReaderIndex();
horn2.resetReaderIndex();
for (int j = 0; j < horn1.writerIndex(); j++) {
Assert.assertEquals(horn1.readByte(), horn2.readByte());
}
}
}
Aggregations