Package net.sf.katta.protocol

Examples of net.sf.katta.protocol.MasterQueue


public class CheckIndicesOperationTest extends AbstractMasterNodeZkTest {

  @Test
  public void testBalanceUnderreplicatedIndex() throws Exception {
    MasterQueue masterQueue = Mocks.publishMaster(_protocol);

    // add nodes and index
    List<Node> nodes = Mocks.mockNodes(2);
    List<NodeQueue> nodeQueues = Mocks.publisNodes(_protocol, nodes);
    deployIndex(nodes, nodeQueues);
    assertEquals(0, masterQueue.size());

    // balance the index does not change anything
    CheckIndicesOperation checkOperation = new CheckIndicesOperation();
    checkOperation.execute(_context, EMPTY_LIST);
    assertEquals(0, masterQueue.size());

    // add node and then balance again
    Node node3 = Mocks.mockNode();
    Mocks.publisNode(_protocol, node3);
    checkOperation.execute(_context, EMPTY_LIST);
    assertEquals(1, masterQueue.size());
  }
View Full Code Here


    assertEquals(1, masterQueue.size());
  }

  @Test
  public void testBalanceOverreplicatedIndex() throws Exception {
    MasterQueue masterQueue = Mocks.publishMaster(_protocol);

    // add nodes and index
    List<Node> nodes = Mocks.mockNodes(3);
    List<NodeQueue> nodeQueues = Mocks.publisNodes(_protocol, nodes);
    deployIndex(nodes, nodeQueues);
    assertEquals(0, masterQueue.size());

    // balance the index does not change anything
    CheckIndicesOperation balanceOperation = new CheckIndicesOperation();
    balanceOperation.execute(_context, EMPTY_LIST);
    assertEquals(0, masterQueue.size());

    // decrease the replication count and then balance again
    IndexMetaData indexMD = _protocol.getIndexMD(_indexName);
    indexMD.setReplicationLevel(2);
    _protocol.updateIndexMD(indexMD);
    balanceOperation.execute(_context, EMPTY_LIST);
    assertEquals(1, masterQueue.size());
  }
View Full Code Here

  @Test
  public void testBecomeMaster() throws Exception {
    final Master master = new Master(_protocol, false);

    MasterQueue masterQueue = mockBlockingOperationQueue();
    when(_protocol.publishMaster(master)).thenReturn(masterQueue);
    when(_protocol.getLiveNodes()).thenReturn(Arrays.asList("node1"));

    master.start();
    assertTrue(master.isMaster());
View Full Code Here

  @Test
  public void testDisconnectReconnect() throws Exception {
    final Master master = new Master(_protocol, false);

    MasterQueue masterQueue = mockBlockingOperationQueue();
    when(_protocol.publishMaster(master)).thenReturn(masterQueue);
    when(_protocol.getLiveNodes()).thenReturn(Arrays.asList("node1"));

    master.start();
    assertTrue(master.isMaster());
View Full Code Here

  @Test
  public void testRemoveOldNodeShards() throws Exception {
    final Master master = new Master(_protocol, false);

    String nodeName = "node1";
    MasterQueue masterQueue = mockBlockingOperationQueue();
    when(_protocol.publishMaster(master)).thenReturn(masterQueue);
    when(_protocol.getLiveNodes()).thenReturn(Arrays.asList(nodeName));
    when(_protocol.registerChildListener(eq(master), eq(PathDef.NODES_LIVE), any(IAddRemoveListener.class)))
            .thenReturn(Arrays.asList(nodeName));
View Full Code Here

      master = new Master(_protocol, zkServer);
    } else {
      master = new Master(_protocol, shutdownClient);
    }

    MasterQueue masterQueue = mockBlockingOperationQueue();
    when(_protocol.publishMaster(master)).thenReturn(masterQueue);
    when(_protocol.getLiveNodes()).thenReturn(Arrays.asList("node1"));

    master.start();
    TestUtil.waitUntilLeaveSafeMode(master);
View Full Code Here

      verify(zkServer).shutdown();
    }
  }

  private MasterQueue mockBlockingOperationQueue() throws InterruptedException {
    MasterQueue queue = mock(MasterQueue.class);
    when(queue.peek()).thenAnswer(new SleepingAnswer());
    return queue;
  }
View Full Code Here

    IndexMetaData newIndexMD = _protocol.getIndexMD(indexName);
    assertEquals(indexName, newIndexMD.getName());
    assertEquals(oldIndexMD.getPath(), newIndexMD.getPath());
    assertEquals(oldIndexMD.getReplicationLevel(), newIndexMD.getReplicationLevel());

    MasterQueue queue = _protocol.publishMaster(Mocks.mockMaster());
    assertEquals(1, queue.size());
    assertThat(queue.peek(), instanceOf(IndexReinitializeOperation.class));
  }
View Full Code Here

  private synchronized void becomePrimaryOrSecondaryMaster() {
    if (isShutdown()) {
      return;
    }
    MasterQueue queue = _protocol.publishMaster(this);
    if (queue != null) {
      UpgradeAction upgradeAction = UpgradeRegistry.findUpgradeAction(_protocol, Version.readFromJar());
      if (upgradeAction != null) {
        upgradeAction.upgrade(_protocol);
      }
      _protocol.setVersion(Version.readFromJar());
      LOG.info(getMasterName() + " became master with " + queue.size() + " waiting master operations");
      startNodeManagement();
      MasterContext masterContext = new MasterContext(_protocol, this, _deployPolicy, queue);
      _operatorThread = new OperatorThread(masterContext, _safeModeMaxTime);
      _operatorThread.start();
    }
View Full Code Here

    assertNotNull(indexMD);
    assertNull(indexMD.getDeployError());

    // balance index should have been be triggered
    Master master = Mocks.mockMaster();
    MasterQueue masterQueue = _protocol.publishMaster(master);
    MasterOperation operation = masterQueue.peek();
    assertNotNull(operation);
    assertTrue(operation instanceof BalanceIndexOperation);
  }
View Full Code Here

TOP

Related Classes of net.sf.katta.protocol.MasterQueue

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.