use of org.apache.activemq.artemis.api.core.client.ClientProducer in project activemq-artemis by apache.
the class InterruptedLargeMessageTest method testSendNonPersistentQueue.
@Test
public void testSendNonPersistentQueue() throws Exception {
ClientSession session = null;
LargeMessageTestInterceptorIgnoreLastPacket.disableInterrupt();
ActiveMQServer server = createServer(true, isNetty());
server.start();
locator.setBlockOnNonDurableSend(true).setBlockOnDurableSend(true);
ClientSessionFactory sf = createSessionFactory(locator);
session = sf.createSession(false, true, true);
session.createQueue(ADDRESS, ADDRESS, false);
ClientProducer producer = session.createProducer(ADDRESS);
for (int i = 0; i < 10; i++) {
Message clientFile = createLargeClientMessageStreaming(session, LARGE_MESSAGE_SIZE, true);
producer.send(clientFile);
}
session.commit();
session.close();
session = sf.createSession(false, false);
ClientConsumer cons = session.createConsumer(ADDRESS);
session.start();
for (int h = 0; h < 5; h++) {
for (int i = 0; i < 10; i++) {
ClientMessage clientMessage = cons.receive(5000);
Assert.assertNotNull(clientMessage);
for (int countByte = 0; countByte < LARGE_MESSAGE_SIZE; countByte++) {
Assert.assertEquals(ActiveMQTestBase.getSamplebyte(countByte), clientMessage.getBodyBuffer().readByte());
}
clientMessage.acknowledge();
}
session.rollback();
}
server.fail(false);
server.start();
server.stop();
validateNoFilesOnLargeDir();
}
use of org.apache.activemq.artemis.api.core.client.ClientProducer in project activemq-artemis by apache.
the class InterruptedLargeMessageTest method testRestartBeforeDelete.
@Test
public void testRestartBeforeDelete() throws Exception {
class NoPostACKQueue extends QueueImpl {
NoPostACKQueue(long id, SimpleString address, SimpleString name, Filter filter, SimpleString user, PageSubscription pageSubscription, boolean durable, boolean temporary, boolean autoCreated, ScheduledExecutorService scheduledExecutor, PostOffice postOffice, StorageManager storageManager, HierarchicalRepository<AddressSettings> addressSettingsRepository, ArtemisExecutor executor) {
super(id, address, name, filter, pageSubscription, user, durable, temporary, autoCreated, scheduledExecutor, postOffice, storageManager, addressSettingsRepository, executor, null, null);
}
@Override
public void postAcknowledge(final MessageReference ref) {
System.out.println("Ignoring postACK on message " + ref);
}
@Override
public void deliverScheduledMessages() {
}
}
final class NoPostACKQueueFactory implements QueueFactory {
final StorageManager storageManager;
final PostOffice postOffice;
final ScheduledExecutorService scheduledExecutor;
final HierarchicalRepository<AddressSettings> addressSettingsRepository;
final ExecutorFactory execFactory;
NoPostACKQueueFactory(StorageManager storageManager, PostOffice postOffice, ScheduledExecutorService scheduledExecutor, HierarchicalRepository<AddressSettings> addressSettingsRepository, final ExecutorFactory execFactory) {
this.storageManager = storageManager;
this.postOffice = postOffice;
this.scheduledExecutor = scheduledExecutor;
this.addressSettingsRepository = addressSettingsRepository;
this.execFactory = execFactory;
}
@Override
public Queue createQueueWith(final QueueConfig config) {
return new NoPostACKQueue(config.id(), config.address(), config.name(), config.filter(), config.user(), config.pageSubscription(), config.isDurable(), config.isTemporary(), config.isAutoCreated(), scheduledExecutor, postOffice, storageManager, addressSettingsRepository, execFactory.getExecutor());
}
@Deprecated
@Override
public Queue createQueue(long persistenceID, SimpleString address, SimpleString name, Filter filter, PageSubscription pageSubscription, SimpleString user, boolean durable, boolean temporary, boolean autoCreated) {
return new NoPostACKQueue(persistenceID, address, name, filter, user, pageSubscription, durable, temporary, autoCreated, scheduledExecutor, postOffice, storageManager, addressSettingsRepository, execFactory.getExecutor());
}
/* (non-Javadoc)
* @see org.apache.activemq.artemis.core.server.QueueFactory#setPostOffice(org.apache.activemq.artemis.core.postoffice.PostOffice)
*/
@Override
public void setPostOffice(PostOffice postOffice) {
}
}
ClientSession session = null;
LargeMessageTestInterceptorIgnoreLastPacket.disableInterrupt();
ActiveMQServer server = createServer(true, isNetty());
server.start();
QueueFactory original = server.getQueueFactory();
((ActiveMQServerImpl) server).replaceQueueFactory(new NoPostACKQueueFactory(server.getStorageManager(), server.getPostOffice(), server.getScheduledPool(), server.getAddressSettingsRepository(), server.getExecutorFactory()));
locator.setBlockOnNonDurableSend(true).setBlockOnDurableSend(true);
ClientSessionFactory sf = createSessionFactory(locator);
session = sf.createSession(false, true, true);
session.createQueue(ADDRESS, ADDRESS, true);
ClientProducer producer = session.createProducer(ADDRESS);
for (int i = 0; i < 10; i++) {
Message clientFile = createLargeClientMessageStreaming(session, LARGE_MESSAGE_SIZE, true);
producer.send(clientFile);
}
session.commit();
session.close();
session = sf.createSession(false, false);
ClientConsumer cons = session.createConsumer(ADDRESS);
session.start();
for (int i = 0; i < 10; i++) {
ClientMessage msg = cons.receive(5000);
Assert.assertNotNull(msg);
msg.saveToOutputStream(new java.io.OutputStream() {
@Override
public void write(int b) throws IOException {
}
});
msg.acknowledge();
session.commit();
}
((ActiveMQServerImpl) server).replaceQueueFactory(original);
server.fail(false);
server.start();
server.stop();
validateNoFilesOnLargeDir();
}
use of org.apache.activemq.artemis.api.core.client.ClientProducer in project activemq-artemis by apache.
the class LargeMessageCompressTest method testLargeMessageCompression3.
@Test
public void testLargeMessageCompression3() 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.saveToOutputStream(output);
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.client.ClientProducer in project activemq-artemis by apache.
the class LargeMessageCompressTest method testLargeMessageCompression.
@Test
public void testLargeMessageCompression() 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);
for (int i = 0; i < messageSize; i++) {
byte b = msg1.getBodyBuffer().readByte();
assertEquals("position = " + i, getSamplebyte(i), b);
}
msg1.acknowledge();
session.commit();
consumer.close();
session.close();
validateNoFilesOnLargeDir();
}
use of org.apache.activemq.artemis.api.core.client.ClientProducer in project activemq-artemis by apache.
the class LargeMessageCompressTest method testHugeStreamingSpacesCompressed.
// This test will send 1 Gig of spaces. There shouldn't be enough memory to uncompress the file in memory
// but this will make sure we can work through compressed channels on saving it to stream
@Test
public void testHugeStreamingSpacesCompressed() throws Exception {
final long messageSize = 1024L * 1024L;
System.out.println("Message size = " + messageSize);
ActiveMQServer server = createServer(true, isNetty());
server.start();
// big enough to hold the whole message compressed on a single message (about 1M on our tests)
locator.setMinLargeMessageSize(100 * 1024 * 1024);
ClientSessionFactory sf = createSessionFactory(locator);
ClientSession session = addClientSession(sf.createSession(false, false, false));
session.createQueue(ADDRESS, ADDRESS, null, true);
ClientProducer producer = session.createProducer(ADDRESS);
ClientMessage clientMessage = session.createMessage(true);
clientMessage.setBodyInputStream(new InputStream() {
private long count;
private boolean closed = false;
@Override
public void close() throws IOException {
super.close();
closed = true;
}
@Override
public int read() throws IOException {
if (closed) {
throw new IOException("Stream was closed");
}
if (count++ < messageSize) {
return ' ';
} else {
return -1;
}
}
});
producer.send(clientMessage);
session.commit();
// this is to make sure the message was sent as a regular message (not taking a file on server)
validateNoFilesOnLargeDir();
session.start();
ClientConsumer consumer = session.createConsumer(ADDRESS);
ClientMessage msg1 = consumer.receive(1000);
Assert.assertNotNull(msg1);
final AtomicLong numberOfSpaces = new AtomicLong();
msg1.saveToOutputStream(new OutputStream() {
@Override
public void write(int content) {
if (content == ' ') {
numberOfSpaces.incrementAndGet();
}
}
});
assertEquals(messageSize, numberOfSpaces.get());
msg1.acknowledge();
session.commit();
session.close();
}
Aggregations