Search in sources :

Example 1 with LogOperation

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();
}
Also used : LogOperation(com.hazelcast.simulator.protocol.operation.LogOperation) SimulatorOperation(com.hazelcast.simulator.protocol.operation.SimulatorOperation) Future(java.util.concurrent.Future) SimulatorAddress(com.hazelcast.simulator.protocol.core.SimulatorAddress)

Example 2 with LogOperation

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());
        }
    });
}
Also used : LogOperation(com.hazelcast.simulator.protocol.operation.LogOperation) SimulatorOperation(com.hazelcast.simulator.protocol.operation.SimulatorOperation) Future(java.util.concurrent.Future) AssertTask(com.hazelcast.simulator.utils.AssertTask) SimulatorAddress(com.hazelcast.simulator.protocol.core.SimulatorAddress) JMSException(javax.jms.JMSException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 3 with LogOperation

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);
    }
}
Also used : LogOperation(com.hazelcast.simulator.protocol.operation.LogOperation) JMSException(javax.jms.JMSException) CountDownLatch(java.util.concurrent.CountDownLatch) SimulatorAddress(com.hazelcast.simulator.protocol.core.SimulatorAddress) JMSException(javax.jms.JMSException) ExecutionException(java.util.concurrent.ExecutionException) SimulatorOperation(com.hazelcast.simulator.protocol.operation.SimulatorOperation) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 4 with LogOperation

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");
}
Also used : ProcessException(com.hazelcast.simulator.protocol.exception.ProcessException) LogOperation(com.hazelcast.simulator.protocol.operation.LogOperation) PerformanceStatsOperation(com.hazelcast.simulator.worker.operations.PerformanceStatsOperation) FailureOperation(com.hazelcast.simulator.coordinator.operations.FailureOperation)

Example 5 with LogOperation

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));
        }
    });
}
Also used : LogOperation(com.hazelcast.simulator.protocol.operation.LogOperation) SimulatorOperation(com.hazelcast.simulator.protocol.operation.SimulatorOperation) AssertTask(com.hazelcast.simulator.utils.AssertTask) SimulatorAddress(com.hazelcast.simulator.protocol.core.SimulatorAddress) JMSException(javax.jms.JMSException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Aggregations

LogOperation (com.hazelcast.simulator.protocol.operation.LogOperation)6 SimulatorAddress (com.hazelcast.simulator.protocol.core.SimulatorAddress)4 SimulatorOperation (com.hazelcast.simulator.protocol.operation.SimulatorOperation)4 ExecutionException (java.util.concurrent.ExecutionException)3 Future (java.util.concurrent.Future)3 JMSException (javax.jms.JMSException)3 Test (org.junit.Test)3 AssertTask (com.hazelcast.simulator.utils.AssertTask)2 FailureOperation (com.hazelcast.simulator.coordinator.operations.FailureOperation)1 ProcessException (com.hazelcast.simulator.protocol.exception.ProcessException)1 PerformanceStatsOperation (com.hazelcast.simulator.worker.operations.PerformanceStatsOperation)1 CountDownLatch (java.util.concurrent.CountDownLatch)1