use of com.hazelcast.simulator.protocol.operation.LogOperation in project hazelcast-simulator by hazelcast.
the class Example method main.
public static void main(String[] args) throws Exception {
String username = "peter";
String password = "password";
Broker broker = new Broker().setCredentials(username, password).start();
CoordinatorClient coordinatorClient = new CoordinatorClient().connectToAgentBroker(SimulatorAddress.fromString("A1"), Inet4Address.getLocalHost().getHostAddress()).start();
Server agentServer = new Server("agents").setProcessor(new OperationProcessor() {
@Override
public void process(SimulatorOperation op, SimulatorAddress source, Promise promise) throws Exception {
}
}).setSelfAddress(SimulatorAddress.fromString("A1")).setBrokerURL(broker.getBrokerURL()).start();
Server workerServer = new Server("workers").setProcessor(new OperationProcessor() {
@Override
public void process(SimulatorOperation op, SimulatorAddress source, Promise promise) throws Exception {
System.out.println("worker:" + op);
}
}).setSelfAddress(SimulatorAddress.fromString("A1_W1")).setBrokerURL(broker.getBrokerURL()).start();
SimulatorAddress address = SimulatorAddress.fromString("A1_W1");
Future f = coordinatorClient.submit(address, new LogOperation("foo"));
System.out.println(f.get());
// client.send(address, new AuthOperation());
Thread.sleep(5000);
agentServer.close();
workerServer.close();
coordinatorClient.close();
broker.close();
}
use of com.hazelcast.simulator.protocol.operation.LogOperation in project hazelcast-simulator by hazelcast.
the class MessagingTest method test.
@Test
public void test() throws Exception {
agentServer = new Server("agents").setBrokerURL(broker.getBrokerURL()).setSelfAddress(agentAddress).setProcessor(new OperationProcessor() {
@Override
public void process(SimulatorOperation op, SimulatorAddress source, Promise promise) throws Exception {
System.out.println(op);
promise.answer("OK");
}
}).start();
client = new CoordinatorClient().setProcessor(mock(OperationProcessor.class)).start().connectToAgentBroker(agentAddress, localIp());
final Future f = client.submit(agentAddress, new LogOperation("", Level.DEBUG));
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertTrue(f.isDone());
assertEquals("OK", f.get());
}
});
}
use of com.hazelcast.simulator.protocol.operation.LogOperation in project hazelcast-simulator by hazelcast.
the class MessagingTest method testWhenAgentConnectionFails.
@Test
public void testWhenAgentConnectionFails() throws Exception {
final CountDownLatch received = new CountDownLatch(1);
agentServer = new Server("agents").setBrokerURL(broker.getBrokerURL()).setSelfAddress(agentAddress).setProcessor(new OperationProcessor() {
@Override
public void process(SimulatorOperation op, SimulatorAddress source, Promise promise) throws Exception {
// we don't do anything to let the future wait
received.countDown();
}
}).start();
client = new CoordinatorClient().setProcessor(mock(OperationProcessor.class));
client.getConnectionFactory().setMaxReconnectAttempts(1);
client.start().connectToAgentBroker(agentAddress, localIp());
final Future f = client.submit(agentAddress, new LogOperation("", Level.DEBUG));
received.await();
broker.close();
assertCompletesEventually(f);
try {
f.get();
fail();
} catch (ExecutionException e) {
assertTrue(e.getCause() instanceof JMSException);
}
}
use of com.hazelcast.simulator.protocol.operation.LogOperation in project hazelcast-simulator by hazelcast.
the class CoordinatorOperationProcessor method process.
@Override
public void process(SimulatorOperation op, SimulatorAddress source, Promise promise) throws Exception {
if (op instanceof FailureOperation) {
failureCollector.notify((FailureOperation) op);
} else if (op instanceof PerformanceStatsOperation) {
performanceStatsCollector.update(source, ((PerformanceStatsOperation) op).getPerformanceStats());
} else if (op instanceof LogOperation) {
LogOperation logOperation = (LogOperation) op;
LOGGER.log(logOperation.getLevel(), logOperation.getMessage());
} else {
throw new ProcessException("Unknown operation:" + op);
}
promise.answer("ok");
}
use of com.hazelcast.simulator.protocol.operation.LogOperation in project hazelcast-simulator by hazelcast.
the class MessagingTest method sendCoordinator.
@Test
public void sendCoordinator() throws Exception {
agentServer = new Server("agents").setBrokerURL(broker.getBrokerURL()).setSelfAddress(agentAddress).setProcessor(new OperationProcessor() {
@Override
public void process(SimulatorOperation op, SimulatorAddress source, Promise promise) throws Exception {
}
}).start();
final OperationProcessor clientOperationProcessor = mock(OperationProcessor.class);
client = new CoordinatorClient().setProcessor(clientOperationProcessor);
client.getConnectionFactory().setMaxReconnectAttempts(1);
client.start().connectToAgentBroker(agentAddress, localIp());
agentServer.sendCoordinator(new LogOperation("Foo"));
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
verify(clientOperationProcessor).process(any(LogOperation.class), eq(agentAddress), any(Promise.class));
}
});
}
Aggregations