Created
August 3, 2012 16:01
-
-
Save clebertsuconic/3248965 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void testFailMessages() throws Exception | |
{ | |
clearData(); | |
Configuration config = createDefaultConfig(); | |
HashMap<String, AddressSettings> settings = new HashMap<String, AddressSettings>(); | |
AddressSettings set = new AddressSettings(); | |
set.setAddressFullMessagePolicy(AddressFullMessagePolicy.FAIL); | |
settings.put(PagingTest.ADDRESS.toString(), set); | |
server = createServer(true, config, 1024, 5 * 1024, settings); | |
server.start(); | |
locator.setBlockOnNonDurableSend(true); | |
locator.setBlockOnDurableSend(true); | |
locator.setBlockOnAcknowledge(true); | |
sf = createSessionFactory(locator); | |
ClientSession session = sf.createSession(true, true, 0); | |
session.createQueue(PagingTest.ADDRESS, PagingTest.ADDRESS, null, true); | |
ClientProducer producer = session.createProducer(PagingTest.ADDRESS); | |
ClientMessage message = null; | |
int biggerMessageSize = 1024; | |
byte[] body = new byte[biggerMessageSize]; | |
ByteBuffer bb = ByteBuffer.wrap(body); | |
for (int j = 1; j <= biggerMessageSize; j++) | |
{ | |
bb.put(getSamplebyte(j)); | |
} | |
// send enough messages to fill up the address | |
for (int i = 0; i < 32; i++) | |
{ | |
message = session.createMessage(true); | |
message.getBodyBuffer().writeBytes(body); | |
producer.send(message); | |
} | |
ClientConsumer consumer = session.createConsumer(ADDRESS); | |
session.start(); | |
for (int i = 0 ; i < 10; i++) | |
{ | |
validateExceptionOnSending(producer, message); | |
} | |
// Receive a message.. this should release credits | |
ClientMessage msgReceived = consumer.receive(5000); | |
assertNotNull(msgReceived); | |
msgReceived.acknowledge(); | |
session.commit(); // to make sure it's on the server (roundtrip) | |
producer.send(message); | |
for (int i = 0 ; i < 10; i++) | |
{ | |
validateExceptionOnSending(producer, message); | |
} | |
} | |
/** | |
* This method validates if sending a message will throw an exception | |
* */ | |
private void validateExceptionOnSending(ClientProducer producer, ClientMessage message) | |
{ | |
HornetQException expected = null; | |
try | |
{ | |
// after the address is full this send should fail (since the address full policy is FAIL) | |
producer.send(message); | |
} | |
catch (HornetQException e) | |
{ | |
e.printStackTrace(); | |
expected = e; | |
} | |
assertNotNull(expected); | |
assertEquals(HornetQExceptionType.ADDRESS_FULL, expected.getType()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment