use of org.apache.activemq.artemis.cli.CLIException in project activemq-artemis by apache.
the class Create method write.
private void write(String source, File target, HashMap<String, String> filters, boolean unixTarget) throws Exception {
if (target.exists() && !force) {
throw new CLIException(String.format("The file '%s' already exists. Use --force to overwrite.", target));
}
String content = readTextFile(source, filters);
// and then writing out in the new target encoding.. Let's also replace \n with the values
// that is correct for the current platform.
String separator = unixTarget && IS_CYGWIN ? "\n" : System.getProperty("line.separator");
content = content.replaceAll("\\r?\\n", Matcher.quoteReplacement(separator));
ByteArrayInputStream in = new ByteArrayInputStream(content.getBytes(encoding));
try (FileOutputStream fout = new FileOutputStream(target)) {
copy(in, fout);
}
}
use of org.apache.activemq.artemis.cli.CLIException in project activemq-artemis by apache.
the class LockAbstract method lockCLI.
void lockCLI(File lockPlace) throws Exception {
if (lockPlace != null) {
lockPlace.mkdirs();
if (serverLockFile == null) {
File fileLock = new File(lockPlace, "cli.lock");
serverLockFile = new RandomAccessFile(fileLock, "rw");
}
try {
FileLock lock = serverLockFile.getChannel().tryLock();
if (lock == null) {
throw new CLIException("Error: There is another process using the server at " + lockPlace + ". Cannot start the process!");
}
serverLockLock = lock;
} catch (OverlappingFileLockException e) {
throw new CLIException("Error: There is another process using the server at " + lockPlace + ". Cannot start the process!");
}
}
}
use of org.apache.activemq.artemis.cli.CLIException in project activemq-artemis by apache.
the class ArtemisTest method testSimpleRun.
public void testSimpleRun(String folderName) throws Exception {
File instanceFolder = temporaryFolder.newFolder(folderName);
setupAuth(instanceFolder);
String queues = "q1,q2";
String addresses = "a1,a2";
// This is usually set when run from the command line via artemis.profile
Run.setEmbedded(true);
Artemis.main("create", instanceFolder.getAbsolutePath(), "--force", "--silent", "--no-web", "--queues", queues, "--addresses", addresses, "--no-autotune", "--require-login");
System.setProperty("artemis.instance", instanceFolder.getAbsolutePath());
try {
// Some exceptions may happen on the initialization, but they should be ok on start the basic core protocol
Artemis.internalExecute("run");
try (ServerLocator locator = ServerLocatorImpl.newLocator("tcp://localhost:61616");
ClientSessionFactory factory = locator.createSessionFactory();
ClientSession coreSession = factory.createSession("admin", "admin", false, true, true, false, 0)) {
for (String str : queues.split(",")) {
ClientSession.QueueQuery queryResult = coreSession.queueQuery(SimpleString.toSimpleString(str));
assertTrue("Couldn't find queue " + str, queryResult.isExists());
}
for (String str : addresses.split(",")) {
ClientSession.AddressQuery queryResult = coreSession.addressQuery(SimpleString.toSimpleString(str));
assertTrue("Couldn't find address " + str, queryResult.isExists());
}
}
try {
Artemis.internalExecute("data", "print");
Assert.fail("Exception expected");
} catch (CLIException expected) {
}
Artemis.internalExecute("data", "print", "--f");
assertEquals(Integer.valueOf(100), Artemis.internalExecute("producer", "--message-count", "100", "--user", "admin", "--password", "admin"));
assertEquals(Integer.valueOf(100), Artemis.internalExecute("consumer", "--break-on-null", "--receive-timeout", "100", "--user", "admin", "--password", "admin"));
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:61616");
Connection connection = cf.createConnection("admin", "admin");
Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
MessageProducer producer = session.createProducer(ActiveMQDestination.createDestination("queue://TEST", ActiveMQDestination.TYPE.QUEUE));
TextMessage message = session.createTextMessage("Banana");
message.setStringProperty("fruit", "banana");
producer.send(message);
for (int i = 0; i < 100; i++) {
message = session.createTextMessage("orange");
message.setStringProperty("fruit", "orange");
producer.send(message);
}
session.commit();
connection.close();
cf.close();
assertEquals(Integer.valueOf(1), Artemis.internalExecute("browser", "--txt-size", "50", "--filter", "fruit='banana'", "--user", "admin", "--password", "admin"));
assertEquals(Integer.valueOf(100), Artemis.internalExecute("browser", "--txt-size", "50", "--filter", "fruit='orange'", "--user", "admin", "--password", "admin"));
assertEquals(Integer.valueOf(101), Artemis.internalExecute("browser", "--txt-size", "50", "--user", "admin", "--password", "admin"));
// should only receive 10 messages on browse as I'm setting messageCount=10
assertEquals(Integer.valueOf(10), Artemis.internalExecute("browser", "--txt-size", "50", "--message-count", "10", "--user", "admin", "--password", "admin"));
// Nothing was consumed until here as it was only browsing, check it's receiving again
assertEquals(Integer.valueOf(1), Artemis.internalExecute("consumer", "--txt-size", "50", "--break-on-null", "--receive-timeout", "100", "--filter", "fruit='banana'", "--user", "admin", "--password", "admin"));
// Checking it was acked before
assertEquals(Integer.valueOf(100), Artemis.internalExecute("consumer", "--txt-size", "50", "--break-on-null", "--receive-timeout", "100", "--user", "admin", "--password", "admin"));
} finally {
stopServer();
}
}
Aggregations