make manual test a little easier to run

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1057179 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary Tully 2011-01-10 13:04:52 +00:00
parent 9e40b914de
commit dce325b144
1 changed files with 44 additions and 16 deletions

View File

@ -36,19 +36,28 @@ import org.junit.Test;
public class NoSpaceIOTest {
private static final Log LOG = LogFactory.getLog(NoSpaceIOTest.class);
// need an app to input to console in intellij idea
public static void main(String[] args) throws Exception {
new NoSpaceIOTest().testRunOutOfSpace();
}
// handy way to validate some out of space related errors with a usb key
// allow it to run out of space, delete toDelete and see it recover
@Ignore("needs small volume, like usb key") @Test
@Ignore("needs small volume, like usb key")
@Test
public void testRunOutOfSpace() throws Exception {
BrokerService broker = new BrokerService();
File dataDir = new File("/Volumes/NO NAME/");
File useUpSpace = new File(dataDir, "bigFile");
if (!useUpSpace.exists()) {
LOG.info("using up some space...");
RandomAccessFile filler = new RandomAccessFile(useUpSpace, "rw");
filler.setLength(1024*1024*1412); // use ~1.5G of 2G (usb) volume
filler.setLength(1024*1024*1212); // use ~1.xG of 2G (usb) volume
filler.close();
File toDelete = new File(dataDir, "toDelete");
filler = new RandomAccessFile(toDelete, "rw");
filler.setLength(1024*1024*32*10); // 10 data files
filler.close();
}
broker.setDataDirectoryFile(dataDir);
broker.start();
@ -60,7 +69,18 @@ public class NoSpaceIOTest {
AtomicLong sent = new AtomicLong(0);
try {
produce(sent, 100);
produce(sent, 200);
} catch (Exception expected) {
LOG.info("got ex, sent: " + sent);
}
LOG.info("sent: " + sent);
System.out.println("Remove toDelete file and press any key to continue");
int read = System.in.read();
System.err.println("read:" + read);
LOG.info("Trying to send again: " + sent);
try {
produce(sent, 200);
} catch (Exception expected) {
LOG.info("got ex, sent: " + sent);
}
@ -69,24 +89,32 @@ public class NoSpaceIOTest {
private void consume(AtomicLong consumed) throws JMSException {
Connection c = new ActiveMQConnectionFactory("vm://localhost").createConnection();
c.start();
Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = s.createConsumer(new ActiveMQQueue("t"));
while (consumer.receive(2000) != null) {
consumed.incrementAndGet();
try {
c.start();
Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = s.createConsumer(new ActiveMQQueue("t"));
while (consumer.receive(2000) != null) {
consumed.incrementAndGet();
}
} finally {
c.close();
}
}
private void produce(AtomicLong sent, long toSend) throws JMSException {
Connection c = new ActiveMQConnectionFactory("vm://localhost").createConnection();
c.start();
Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = s.createProducer(new ActiveMQQueue("t"));
TextMessage m = s.createTextMessage();
m.setText(String.valueOf(new char[1024*1024]));
for (int i=0; i<toSend; i++) {
producer.send(m);
sent.incrementAndGet();
try {
c.start();
Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = s.createProducer(new ActiveMQQueue("t"));
TextMessage m = s.createTextMessage();
m.setText(String.valueOf(new char[1024*1024]));
for (int i=0; i<toSend; i++) {
producer.send(m);
sent.incrementAndGet();
}
} finally {
c.close();
}
}
}