Package net.sf.katta.operation.node

Examples of net.sf.katta.operation.node.NodeOperation


    @Override
    public void run() {
      try {
        while (_nodeContext.getNode().isRunning()) {
          try {
            NodeOperation operation = _queue.peek();
            OperationResult operationResult;
            try {
              LOG.info("executing " + operation);
              operationResult = operation.execute(_nodeContext);
            } catch (Exception e) {
              ExceptionUtil.rethrowInterruptedException(e);
              LOG.error(_nodeContext.getNode().getName() + ": failed to execute " + operation, e);
              operationResult = new OperationResult(_nodeContext.getNode().getName(), e);
            }
View Full Code Here


    when(_protocol.publishNode(eq(_node), (NodeMetaData) notNull())).thenReturn(_queue);
  }

  @Test
  public void testGracefulStartup_Shutdown() throws Exception {
    NodeOperation nodeOperation = mock(NodeOperation.class);
    when(_queue.peek()).thenReturn(nodeOperation).thenAnswer(new SleepingAnswer());

    _node.start();

    assertNotNull(_node.getName());
View Full Code Here

  }

  @Test(timeout = 15000)
  public void testResultMechanism() throws Exception {
    final NodeQueue queue = new NodeQueue(_zk.getZkClient(), getRootPath());
    NodeOperation nodeOperation = mock(NodeOperation.class);
    String elementId = queue.add(nodeOperation);

    assertNotNull(queue.peek());
    OperationResult result = new OperationResult("ndoe1");
    queue.complete(result);
View Full Code Here

    String elementId = "operation-0000000000"; // cheat, we know the internals
    assertNull(queue.getResult(elementId, false));
    _zk.getZkClient().createPersistent(getRootPath() + "/results/" + elementId, "");
    assertNotNull(queue.getResult(elementId, false));

    NodeOperation nodeOperation = mock(NodeOperation.class);
    queue.add(nodeOperation);
    assertNull(queue.getResult(elementId, false));
  }
View Full Code Here

    verify(_contentServer).shutdown();
  }

  @Test
  public void testDisconnectReconnect() throws Exception {
    NodeOperation nodeOperation = mock(NodeOperation.class);
    when(_queue.peek()).thenReturn(nodeOperation).thenAnswer(new SleepingAnswer());
    _node.start();
    Thread.sleep(200);
    verify(nodeOperation, times(1)).execute((NodeContext) notNull());

    _node.disconnect();
    NodeOperation nodeOperation2 = mock(NodeOperation.class);
    reset(_queue);
    when(_queue.peek()).thenReturn(nodeOperation2).thenAnswer(new SleepingAnswer());

    _node.reconnect();
    Thread.sleep(200);
View Full Code Here

  @Test(timeout = 15000)
  public void testResultCleanup() throws Exception {
    ZkClient zkClientSpy = spy(_zk.getZkClient());
    NodeQueue queue = new NodeQueue(zkClientSpy, getRootPath());
    NodeOperation nodeOperation = mock(NodeOperation.class);
    String elementName = queue.add(nodeOperation);

    OperationResult result = new OperationResult("node1");
    // cause a unclean state
    doThrow(new IllegalStateException("test exception")).when(zkClientSpy).delete(endsWith(elementName));
View Full Code Here

    verify(_protocol, never()).disconnect();
  }

  @Test
  public void testRedployInstalledShards() throws Exception {
    NodeOperation nodeOperation = mock(NodeOperation.class);
    when(_queue.peek()).thenReturn(nodeOperation).thenAnswer(new SleepingAnswer());

    // start and add shard
    _node.start();
    verify(_contentServer, times(0)).addShard(anyString(), any(File.class));
View Full Code Here

    OperationWatchdog operationWatchdog = beginMasterOperation(_nodes, _masterOperation);

    // execute node operations
    List<OperationResult> operationResults = new ArrayList<OperationResult>();
    for (NodeQueue nodeQueue : nodeQueues) {
      NodeOperation nodeOperation = nodeQueue.peek();
      assertNotNull(nodeOperation);
      nodeQueue.remove();
      operationResults.add(null);
    }
    operationWatchdog.join();
View Full Code Here

    // execute node operations
    List<OperationResult> operationResults = new ArrayList<OperationResult>();
    int i = 0;
    for (NodeQueue nodeQueue : nodeQueues) {
      NodeOperation nodeOperation = nodeQueue.peek();
      assertNotNull(nodeOperation);
      OperationResult result = new OperationResult(_nodes.get(i).getName());
      operationResults.add(result);
      nodeQueue.complete(result);
      i++;
View Full Code Here

    when(node.getName()).thenReturn(nodeName);

    InteractionProtocol protocol = _zk.getInteractionProtocol();
    NodeQueue nodeQueue = protocol.publishNode(node, new NodeMetaData());

    NodeOperation nodeOperation1 = mock(NodeOperation.class, withSettings().serializable().name("a"));
    NodeOperation nodeOperation2 = mock(NodeOperation.class, withSettings().serializable().name("b"));
    OperationId operation1Id = protocol.addNodeOperation(nodeName, nodeOperation1);
    OperationId operation2Id = protocol.addNodeOperation(nodeName, nodeOperation2);

    assertTrue(protocol.isNodeOperationQueued(operation1Id));
    assertTrue(protocol.isNodeOperationQueued(operation2Id));
    assertEquals(nodeOperation1.toString(), nodeQueue.remove().toString());
    assertEquals(nodeOperation2.toString(), nodeQueue.remove().toString());
    assertTrue(nodeQueue.isEmpty());
    assertFalse(protocol.isNodeOperationQueued(operation1Id));
    assertFalse(protocol.isNodeOperationQueued(operation2Id));
  }
View Full Code Here

TOP

Related Classes of net.sf.katta.operation.node.NodeOperation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.