Package com.splout.db.hazelcast

Examples of com.splout.db.hazelcast.CoordinationStructures


  public void testInitDNodeList() throws Throwable {
    SploutConfiguration config = SploutConfiguration.getTestConfig();
    QNodeHandler handler = new QNodeHandler();
    try {
      HazelcastInstance hz = Hazelcast.newHazelcastInstance(HazelcastConfigBuilder.build(config));
      CoordinationStructures coord = new CoordinationStructures(hz);

      SploutConfiguration dNodeConfig = SploutConfiguration.getTestConfig();
      dNodeConfig.setProperty(DNodeProperties.PORT, 1000);

      coord.getDNodes().put("/localhost:1000", new DNodeInfo(dNodeConfig));

      dNodeConfig = SploutConfiguration.getTestConfig();
      dNodeConfig.setProperty(DNodeProperties.PORT, 1001);

      coord.getDNodes().put("/localhost:1001", new DNodeInfo(dNodeConfig));

      try {
        handler.init(config);
      } catch(Exception e) {
        // since the handler will try to connect to "localhost:1000" we skip the Exception and continue
View Full Code Here


  public void testDNodeDownAndUp() throws Throwable {
    SploutConfiguration config = SploutConfiguration.getTestConfig();
    QNodeHandler handler = new QNodeHandler();
    HazelcastInstance hz = Hazelcast.newHazelcastInstance(HazelcastConfigBuilder.build(config));
    try {
      CoordinationStructures coord = new CoordinationStructures(hz);
      SploutConfiguration dNodeConfig = SploutConfiguration.getTestConfig();
      dNodeConfig.setProperty(DNodeProperties.PORT, 1000);
      coord.getDNodes().put("/localhost:1000", new DNodeInfo(dNodeConfig));

      try {
        handler.init(config);
      } catch(Exception e) {
        // since the handler will try to connect to "localhost:1000" we skip the Exception and continue
        // the things we want to assert should be present anyway.
      }
      Assert.assertEquals(handler.getContext().getCoordinationStructures().getDNodes().values().size(),
          1);

      coord.getDNodes().remove(coord.getDNodes().entrySet().iterator().next().getKey());

      Thread.sleep(100);
      Assert.assertEquals(handler.getContext().getCoordinationStructures().getDNodes().values().size(),
          0);

      dNodeConfig = SploutConfiguration.getTestConfig();
      dNodeConfig.setProperty(DNodeProperties.PORT, 1001);
      coord.getDNodes().put("/localhost:1001", new DNodeInfo(dNodeConfig));
      Thread.sleep(100);

      Assert.assertEquals(handler.getContext().getCoordinationStructures().getDNodes().values().size(),
          1);

      dNodeConfig = SploutConfiguration.getTestConfig();
      dNodeConfig.setProperty(DNodeProperties.PORT, 1000);
      coord.getDNodes().put("/localhost:1000", new DNodeInfo(dNodeConfig));
      Thread.sleep(100);

      Assert.assertEquals(handler.getContext().getCoordinationStructures().getDNodes().values().size(),
          2);

      coord.getDNodes().remove(coord.getDNodes().entrySet().iterator().next().getKey());
      coord.getDNodes().remove(coord.getDNodes().entrySet().iterator().next().getKey());

      Thread.sleep(100);
      Assert.assertEquals(handler.getContext().getCoordinationStructures().getDNodes().values().size(),
          0);
    } finally {
View Full Code Here

    httpExchanger = new HttpFileExchanger(config, new FileReceiverCallback());
    httpExchanger.init();
    httpExchanger.start();
    // Connect with the cluster.
    hz = Hazelcast.newHazelcastInstance(HazelcastConfigBuilder.build(config));
    coord = new CoordinationStructures(hz);
    coord.getDNodeReplicaBalanceActionsSet().addEntryListener(new BalanceActionItemListener(), false);
    // Add shutdown hook
    Runtime.getRuntime().addShutdownHook(new Thread() {
      @Override
      public void run() {
View Full Code Here

      // This is a "soft-restart" after a "soft-shutdown".
      // It is designed for unit and integration testing.
      shutDownByTestAPI.set(false);
      try {
        hz = Hazelcast.newHazelcastInstance(HazelcastConfigBuilder.build(config));
        coord = new CoordinationStructures(hz);
        log.info("Received a restart by test API.");
        giveGreenLigth();
      } catch(HazelcastConfigBuilderException e) {
        log.error("Error while trying to connect to Hazelcast", e);
        throw new DNodeException(EXCEPTION_UNEXPECTED, e.getMessage());
View Full Code Here

    final QNodeHandler handler = new QNodeHandler();
    SploutConfiguration config = SploutConfiguration.getTestConfig();
    try {

      HazelcastInstance hz = Hazelcast.newHazelcastInstance(HazelcastConfigBuilder.build(config));
      CoordinationStructures coord = new CoordinationStructures(hz);
      /*
       * Create 5 successful versions. current-version will be set to last one.
       */
     
      // TODO
     
//      coord.getTablespaces().put(new TablespaceVersion("t1", 0l), new Tablespace(null, null, 0l, 0l));
//      coord.getTablespaces().put(new TablespaceVersion("t1", 1l), new Tablespace(null, null, 1l, 0l));
//      coord.getTablespaces().put(new TablespaceVersion("t1", 2l), new Tablespace(null, null, 2l, 0l));
//      coord.getTablespaces().put(new TablespaceVersion("t1", 3l), new Tablespace(null, null, 3l, 0l));
//      coord.getTablespaces().put(new TablespaceVersion("t1", 4l), new Tablespace(null, null, 4l, 0l));

      Map<String, Long> versionsBeingServed = new HashMap<String, Long>();
      versionsBeingServed.put("t1", 4l);
      coord.getVersionsBeingServed().put(CoordinationStructures.VERSIONS_BEING_SERVED, versionsBeingServed);

      handler.init(config);
     
      List<SwitchVersionRequest> rRequest = new ArrayList<SwitchVersionRequest>();
      SwitchVersionRequest theRequest = new SwitchVersionRequest("t1", 3);
      rRequest.add(theRequest);
      handler.rollback(rRequest);
     
      new TestUtils.NotWaitingForeverCondition() {
        @Override
        public boolean endCondition() {
          return handler.getContext().getCurrentVersionsMap().get("t1") != null &&
              handler.getContext().getCurrentVersionsMap().get("t1") == 3l;
        }
      }.waitAtMost(5000);
     
      assertEquals(3l, (long)coord.getCopyVersionsBeingServed().get("t1"));
     
      /*
       * Changing our mind : now back to previous version 4
       */
      theRequest = new SwitchVersionRequest("t1", 4);
      rRequest = new ArrayList<SwitchVersionRequest>();
      rRequest.add(theRequest);
      handler.rollback(rRequest);
           
      new TestUtils.NotWaitingForeverCondition() {
        @Override
        public boolean endCondition() {
          return handler.getContext().getCurrentVersionsMap().get("t1") != null &&
              handler.getContext().getCurrentVersionsMap().get("t1") == 4l;
        }
      }.waitAtMost(5000);
     
      assertEquals(4l, (long)coord.getCopyVersionsBeingServed().get("t1"));
    } finally {
      handler.close();
      Hazelcast.shutdownAll();
    }
  }
View Full Code Here

    // Here we will have more than one tablespace and we will rollback them all
    final QNodeHandler handler = new QNodeHandler();
    SploutConfiguration config = SploutConfiguration.getTestConfig();
    try {
      HazelcastInstance hz = Hazelcast.newHazelcastInstance(HazelcastConfigBuilder.build(config));
      CoordinationStructures coord = new CoordinationStructures(hz);
     
      /*
       * Create 5 successful versions. current-version will be set to last one.
       */
     
      // TODO
     
//      for(int i = 0; i < 5; i++) {
//        coord.getTablespaces().put(new TablespaceVersion("t1", i), new Tablespace(null, null, i, 0l));
//        coord.getTablespaces().put(new TablespaceVersion("t2", i), new Tablespace(null, null, i, 0l));
//        coord.getTablespaces().put(new TablespaceVersion("t3", i), new Tablespace(null, null, i, 0l));
//      }
     
      // T1 -> current version 4
      // T2 -> current version 3
      // T3 -> current version 2
      Map<String, Long> versionsBeingServed = new HashMap<String, Long>();
      versionsBeingServed.put("t1", 4l);
      versionsBeingServed.put("t2", 3l);
      versionsBeingServed.put("t3", 2l);
      coord.getVersionsBeingServed().put(CoordinationStructures.VERSIONS_BEING_SERVED, versionsBeingServed);
     
      handler.init(config);
     
      List<SwitchVersionRequest> rRequest = new ArrayList<SwitchVersionRequest>();

      // T1 -> rollback to version 2
      // T2 -> rollback to version 1
      // T3 -> rollback to version 0
      SwitchVersionRequest theRequest = new SwitchVersionRequest("t1", 2l);
      rRequest.add(theRequest);
      theRequest = new SwitchVersionRequest("t2", 1l);
      rRequest.add(theRequest);
      theRequest = new SwitchVersionRequest("t3", 0l);
      rRequest.add(theRequest);
     
      handler.rollback(rRequest);
     
      new TestUtils.NotWaitingForeverCondition() {
        @Override
        public boolean endCondition() {
          return
              handler.getContext().getCurrentVersionsMap().get("t1") != null &&
              handler.getContext().getCurrentVersionsMap().get("t1") == 2l;
        }
      }.waitAtMost(5000);

      assertEquals(2l, (long)coord.getCopyVersionsBeingServed().get("t1"));
      assertEquals(1l, (long)coord.getCopyVersionsBeingServed().get("t2"));
      assertEquals(0l, (long)coord.getCopyVersionsBeingServed().get("t3"));
     
      assertEquals(2l, (long)handler.getContext().getCurrentVersionsMap().get("t1"));
      assertEquals(1l, (long)handler.getContext().getCurrentVersionsMap().get("t2"));
      assertEquals(0l, (long)handler.getContext().getCurrentVersionsMap().get("t3"));
     
View Full Code Here

   * Use this method to get a high-level client for Hazelcast in unit tests.
   * @throws HazelcastConfigBuilderException
   */
  public static CoordinationStructures getCoordinationStructures(SploutConfiguration testConfig) throws HazelcastConfigBuilderException {
    HazelcastInstance hz = Hazelcast.newHazelcastInstance(HazelcastConfigBuilder.build(testConfig));
    CoordinationStructures coord = new CoordinationStructures(hz);
    return coord;
  }
View Full Code Here

    handler.init(config);
    config.setProperty(QNodeProperties.VERSIONS_PER_TABLESPACE, 5);
    try {

      HazelcastInstance hz = Hazelcast.newHazelcastInstance(HazelcastConfigBuilder.build(config));
      CoordinationStructures coord = new CoordinationStructures(hz);
     
      handler.init(config);

      for(int i = 0; i < 8; i++) {
        handler.getContext().getTablespaceVersionsMap().put(new TablespaceVersion("t1", i), new Tablespace(null, null, i, 0l));
      }
     
      Map<String, Long> versionsBeingServed = new HashMap<String, Long>();
      versionsBeingServed.put("t1", 6l);
      coord.getVersionsBeingServed().put(CoordinationStructures.KEY_FOR_VERSIONS_BEING_SERVED, versionsBeingServed);
     
      Thread.sleep(300);
     
      List<com.splout.db.thrift.TablespaceVersion> tablespacesToRemove = handler.getContext().synchronizeTablespaceVersions();
View Full Code Here

      final DNodeHandler handler = new DNodeHandler();
      dnode = TestUtils.getTestDNode(testConfig, handler, "dnode-" + this.getClass().getName() + "-4", true);

      // Assert that this DNode is registered for failover
      HazelcastInstance hz = Hazelcast.newHazelcastInstance(HazelcastConfigBuilder.build(testConfig));
      final CoordinationStructures coord = new CoordinationStructures(hz);
      // We need to implement the {@link com.splout.db.hazelcast.DistributedRegistry} for members to be
      // automatically removed from the DNODES map
      new DistributedRegistry(CoordinationStructures.DNODES, new DNodeInfo(testConfig), hz, 10, 3);

      new TestUtils.NotWaitingForeverCondition() {
        @Override
        public boolean endCondition() {
          boolean registered = false;
          for(DNodeInfo info: coord.getDNodes().values()) {
            if(info.getAddress().equals(handler.whoAmI())) {
              registered = true;
            }
          }
          return registered;
        }
      }.waitAtMost(WAIT_AT_MOST);

      dnode.stop();
      dnode = null;

      new TestUtils.NotWaitingForeverCondition() {
        @Override
        public boolean endCondition() {
          boolean unregistered = true;
          for(DNodeInfo info: coord.getDNodes().values()) {
            if(info.getAddress().equals(handler.whoAmI())) {
              unregistered = false;
            }
          }
          return unregistered;
View Full Code Here

    final QNodeHandler handler = new QNodeHandler();
    SploutConfiguration config = SploutConfiguration.getTestConfig();
    try {

      HazelcastInstance hz = Hazelcast.newHazelcastInstance(HazelcastConfigBuilder.build(config));
      CoordinationStructures coord = new CoordinationStructures(hz);

      handler.init(config);

      Map<String, Long> versionsBeingServed = new HashMap<String, Long>();
      versionsBeingServed.put("t1", 0l);
      coord.getVersionsBeingServed().put(CoordinationStructures.KEY_FOR_VERSIONS_BEING_SERVED,
          versionsBeingServed);

      versionsBeingServed.put("t2", 1l);
      coord.getVersionsBeingServed().put(CoordinationStructures.KEY_FOR_VERSIONS_BEING_SERVED,
          versionsBeingServed);

      new TestUtils.NotWaitingForeverCondition() {
       
        @Override
        public boolean endCondition() {
          return handler.getContext().getCurrentVersionsMap().get("t1") != null && handler.getContext().getCurrentVersionsMap().get("t1") == 0l
          && handler.getContext().getCurrentVersionsMap().get("t2") != null && handler.getContext().getCurrentVersionsMap().get("t2") == 1l;
        }
      }.waitAtMost(5000);

      versionsBeingServed.put("t2", 0l);
      versionsBeingServed.put("t1", 1l);
      coord.getVersionsBeingServed().put(CoordinationStructures.KEY_FOR_VERSIONS_BEING_SERVED,
          versionsBeingServed);

      new TestUtils.NotWaitingForeverCondition() {
       
        @Override
        public boolean endCondition() {
          return handler.getContext().getCurrentVersionsMap().get("t1") != null && handler.getContext().getCurrentVersionsMap().get("t1") == 1l
          && handler.getContext().getCurrentVersionsMap().get("t2") != null && handler.getContext().getCurrentVersionsMap().get("t2") == 0l;
        }
      }.waitAtMost(5000);

      versionsBeingServed.put("t2", 1l);
      versionsBeingServed.put("t1", 0l);
      coord.getVersionsBeingServed().put(CoordinationStructures.KEY_FOR_VERSIONS_BEING_SERVED,
          versionsBeingServed);

      Thread.sleep(100);

      Assert.assertEquals(0l, (long) handler.getContext().getCurrentVersionsMap().get("t1"));
View Full Code Here

TOP

Related Classes of com.splout.db.hazelcast.CoordinationStructures

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.