Example #1
0
  @Test
  public void testDropDatabaseWithAllTables() throws Exception {
    Map<String, List<String>> createdTablesMap = createBaseDatabaseAndTables();

    // Each time we drop one database, check all databases and their tables.
    for (String databaseName : new ArrayList<>(createdTablesMap.keySet())) {
      // drop one database
      assertTrue(catalog.existDatabase(databaseName));
      catalog.dropDatabase(databaseName);
      createdTablesMap.remove(databaseName);

      // check all tables which belong to other databases
      for (Map.Entry<String, List<String>> entry : createdTablesMap.entrySet()) {
        assertTrue(catalog.existDatabase(entry.getKey()));

        // checking all tables for this database
        Collection<String> tablesForThisDatabase = catalog.getAllTableNames(entry.getKey());
        assertEquals(createdTablesMap.get(entry.getKey()).size(), tablesForThisDatabase.size());
        for (String tableName : tablesForThisDatabase) {
          assertTrue(
              createdTablesMap
                  .get(entry.getKey())
                  .contains(IdentifierUtil.extractSimpleName(tableName)));
        }
      }
    }

    // Finally, default and system database will remain. So, its result is 1.
    assertEquals(2, catalog.getAllDatabaseNames().size());
  }
 @Test
 public void testNetworkConfig() {
   NetworkConfig networkConfig = config.getNetworkConfig();
   assertNotNull(networkConfig);
   assertEquals(5700, networkConfig.getPort());
   assertFalse(networkConfig.isPortAutoIncrement());
   final Collection<String> allowedPorts = networkConfig.getOutboundPortDefinitions();
   assertEquals(2, allowedPorts.size());
   Iterator portIter = allowedPorts.iterator();
   assertEquals("35000-35100", portIter.next());
   assertEquals("36000,36100", portIter.next());
   assertFalse(networkConfig.getJoin().getMulticastConfig().isEnabled());
   assertEquals(networkConfig.getJoin().getMulticastConfig().getMulticastTimeoutSeconds(), 8);
   assertEquals(networkConfig.getJoin().getMulticastConfig().getMulticastTimeToLive(), 16);
   assertFalse(networkConfig.getInterfaces().isEnabled());
   assertEquals(1, networkConfig.getInterfaces().getInterfaces().size());
   assertEquals("10.10.1.*", networkConfig.getInterfaces().getInterfaces().iterator().next());
   TcpIpConfig tcp = networkConfig.getJoin().getTcpIpConfig();
   assertNotNull(tcp);
   assertTrue(tcp.isEnabled());
   assertTrue(networkConfig.getSymmetricEncryptionConfig().isEnabled());
   final List<String> members = tcp.getMembers();
   assertEquals(members.toString(), 2, members.size());
   assertEquals("127.0.0.1:5700", members.get(0));
   assertEquals("127.0.0.1:5701", members.get(1));
   assertEquals("127.0.0.1:5700", tcp.getRequiredMember());
   AwsConfig aws = networkConfig.getJoin().getAwsConfig();
   assertFalse(aws.isEnabled());
   assertEquals("sample-access-key", aws.getAccessKey());
   assertEquals("sample-secret-key", aws.getSecretKey());
   assertEquals("sample-region", aws.getRegion());
   assertEquals("sample-group", aws.getSecurityGroupName());
   assertEquals("sample-tag-key", aws.getTagKey());
   assertEquals("sample-tag-value", aws.getTagValue());
 }
Example #3
0
  @Test
  public void test_construction_permutations() {
    for (int a = 0; a < 6; a++) {
      compare_order(newSet(a), setOf(a));
      for (int b = 0; b < 6; b++) {
        compare_order(newSet(a, b), setOf(a, b));
        for (int c = 0; c < 6; c++) {
          compare_order(newSet(a, b, c), setOf(a, b, c));
          for (int d = 0; d < 6; d++) {
            compare_order(newSet(a, b, c, d), setOf(a, b, c, d));
            for (int e = 0; e < 6; e++) {
              compare_order(newSet(a, b, c, d, e), setOf(a, b, c, d, e));
              for (int f = 0; f < 6; f++) {
                Integer[] elements = new Integer[] {a, b, c, d, e, f};
                Set<Integer> expected = newSet(elements);
                Collection<Integer> collection = Arrays.asList(elements);

                // setOf
                compare_order(expected, setOf(a, b, c, d, e, f));
                // asSet(array)
                compare_order(expected, asSet(elements));
                // asSet(collection)
                compare_order(expected, asSet(collection));
                // asSet(iterator)
                compare_order(expected, asSet(collection.iterator()));
              }
            }
          }
        }
      }
    }
  }
 @Test
 public void values() throws InterruptedException {
   HazelcastClient hClient = getHazelcastClient();
   MultiMap<String, String> multiMap = hClient.getMultiMap("entrySet");
   Map<String, List<String>> valueKeyListMap = new HashMap<String, List<String>>();
   int count = 100;
   for (int i = 0; i < count; i++) {
     for (int j = 0; j <= i; j++) {
       String key = String.valueOf(i);
       String value = String.valueOf(j);
       multiMap.put(key, value);
       if (valueKeyListMap.get(value) == null) {
         valueKeyListMap.put(value, new ArrayList<String>());
       }
       valueKeyListMap.get(value).add(key);
     }
   }
   assertEquals(count * (count + 1) / 2, multiMap.size());
   Collection<String> collection = multiMap.values();
   assertEquals(count * (count + 1) / 2, collection.size());
   Iterator<String> iterator = collection.iterator();
   System.out.println(iterator.getClass());
   for (; iterator.hasNext(); ) {
     String value = iterator.next();
     assertNotNull(valueKeyListMap.get(value).remove(0));
     if (valueKeyListMap.get(value).size() == 0) {
       valueKeyListMap.remove(value);
     }
   }
   assertTrue(valueKeyListMap.isEmpty());
 }
Example #5
0
  @Test
  public void testCompactionLog() throws Exception {
    SystemKeyspace.discardCompactionsInProgress();

    String cf = "Standard4";
    ColumnFamilyStore cfs = Keyspace.open(KEYSPACE1).getColumnFamilyStore(cf);
    SchemaLoader.insertData(KEYSPACE1, cf, 0, 1);
    cfs.forceBlockingFlush();

    Collection<SSTableReader> sstables = cfs.getSSTables();
    assertFalse(sstables.isEmpty());
    Set<Integer> generations =
        Sets.newHashSet(
            Iterables.transform(
                sstables,
                new Function<SSTableReader, Integer>() {
                  public Integer apply(SSTableReader sstable) {
                    return sstable.descriptor.generation;
                  }
                }));
    UUID taskId = SystemKeyspace.startCompaction(cfs, sstables);
    Map<Pair<String, String>, Map<Integer, UUID>> compactionLogs =
        SystemKeyspace.getUnfinishedCompactions();
    Set<Integer> unfinishedCompactions = compactionLogs.get(Pair.create(KEYSPACE1, cf)).keySet();
    assertTrue(unfinishedCompactions.containsAll(generations));

    SystemKeyspace.finishCompaction(taskId);
    compactionLogs = SystemKeyspace.getUnfinishedCompactions();
    assertFalse(compactionLogs.containsKey(Pair.create(KEYSPACE1, cf)));
  }
Example #6
0
  @Test
  public void testCreateAndDropManyDatabases() throws Exception {
    List<String> createdDatabases = new ArrayList<>();
    InfoSchemaMetadataDictionary dictionary = new InfoSchemaMetadataDictionary();
    String namePrefix = "database_";
    final int NUM = 10;
    for (int i = 0; i < NUM; i++) {
      String databaseName = namePrefix + i;
      assertFalse(catalog.existDatabase(databaseName));
      catalog.createDatabase(databaseName, TajoConstants.DEFAULT_TABLESPACE_NAME);
      assertTrue(catalog.existDatabase(databaseName));
      createdDatabases.add(databaseName);
    }

    Collection<String> allDatabaseNames = catalog.getAllDatabaseNames();
    for (String databaseName : allDatabaseNames) {
      assertTrue(
          databaseName.equals(DEFAULT_DATABASE_NAME)
              || createdDatabases.contains(databaseName)
              || dictionary.isSystemDatabase(databaseName));
    }
    // additional ones are 'default' and 'system' databases.
    assertEquals(NUM + 2, allDatabaseNames.size());

    Collections.shuffle(createdDatabases);
    for (String tobeDropped : createdDatabases) {
      assertTrue(catalog.existDatabase(tobeDropped));
      catalog.dropDatabase(tobeDropped);
      assertFalse(catalog.existDatabase(tobeDropped));
    }
  }
Example #7
0
  @Test
  public void testCookies_whenCookiesArePresent() {

    Collection<Cookie> cookies = new ArrayList<>();
    cookies.add(new Cookie("cookie1", "cookie1value"));
    cookies.add(new Cookie("cookie2", "cookie2value"));

    Map<String, String> expected = new HashMap<>();
    for (Cookie cookie : cookies) {
      expected.put(cookie.getName(), cookie.getValue());
    }

    Cookie[] cookieArray = cookies.toArray(new Cookie[cookies.size()]);

    when(servletRequest.getCookies()).thenReturn(cookieArray);

    assertTrue(
        "The count of cookies returned should be the same as those in the request",
        request.cookies().size() == 2);

    assertEquals(
        "A Map of Cookies should have been returned because they exist",
        expected,
        request.cookies());
  }
Example #8
0
  @Test
  public void testEchoedRow() throws IOException, ExecutionException, InterruptedException {
    // This test check that EchoedRow doesn't skipp rows: see CASSANDRA-2653

    Keyspace keyspace = Keyspace.open(KEYSPACE1);
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore("Standard2");

    // disable compaction while flushing
    cfs.disableAutoCompaction();

    // Insert 4 keys in two sstables. We need the sstables to have 2 rows
    // at least to trigger what was causing CASSANDRA-2653
    for (int i = 1; i < 5; i++) {
      DecoratedKey key = Util.dk(String.valueOf(i));
      RowMutation rm = new RowMutation(KEYSPACE1, key.key);
      rm.add(
          "Standard2",
          ByteBufferUtil.bytes(String.valueOf(i)),
          ByteBufferUtil.EMPTY_BYTE_BUFFER,
          i);
      rm.apply();

      if (i % 2 == 0) cfs.forceBlockingFlush();
    }
    Collection<SSTableReader> toCompact = cfs.getSSTables();
    assert toCompact.size() == 2;

    // Reinserting the same keys. We will compact only the previous sstable, but we need those new
    // ones
    // to make sure we use EchoedRow, otherwise it won't be used because purge can be done.
    for (int i = 1; i < 5; i++) {
      DecoratedKey key = Util.dk(String.valueOf(i));
      RowMutation rm = new RowMutation(KEYSPACE1, key.key);
      rm.add(
          "Standard2",
          ByteBufferUtil.bytes(String.valueOf(i)),
          ByteBufferUtil.EMPTY_BYTE_BUFFER,
          i);
      rm.apply();
    }
    cfs.forceBlockingFlush();
    SSTableReader tmpSSTable = null;
    for (SSTableReader sstable : cfs.getSSTables())
      if (!toCompact.contains(sstable)) tmpSSTable = sstable;
    assert tmpSSTable != null;

    // Force compaction on first sstables. Since each row is in only one sstable, we will be using
    // EchoedRow.
    Util.compact(cfs, toCompact);
    assertEquals(2, cfs.getSSTables().size());

    // Now, we remove the sstable that was just created to force the use of EchoedRow (so that it
    // doesn't hide the problem)
    cfs.markObsolete(Collections.singleton(tmpSSTable), OperationType.UNKNOWN);
    assertEquals(1, cfs.getSSTables().size());

    // Now assert we do have the 4 keys
    assertEquals(4, Util.getRangeSlice(cfs).size());
  }
 // Check all iterators for correct size counts
 private void checkSizes(int expectedSize) {
   assertEquals("size()", _nbhm.size(), expectedSize);
   Collection<String> vals = _nbhm.values();
   checkSizes("values()", vals.size(), vals.iterator(), expectedSize);
   Set<String> keys = _nbhm.keySet();
   checkSizes("keySet()", keys.size(), keys.iterator(), expectedSize);
   Set<Entry<String, String>> ents = _nbhm.entrySet();
   checkSizes("entrySet()", ents.size(), ents.iterator(), expectedSize);
 }
Example #10
0
  @Test
  public void resultCanBeExtractedAsHashSet() {
    assertThat($(integerInput).asHashSet(), instanceOf(HashSet.class));

    Collection<String> stringInputAsSet = $(stringInput).asCollection();

    assertTrue($(stringInput).asHashSet().containsAll(stringInputAsSet));
    assertTrue(stringInputAsSet.containsAll($(stringInput).asHashSet()));
  }
Example #11
0
 @Test
 public void test_publicInterfaceRef_annotation_present() {
   Collection<Integer> elements = new ArrayList<>();
   for (int i = 0; i < 15; i++) {
     assertSame(
         BasicConstSet.class,
         asSet(elements).getClass().getAnnotation(PublicInterfaceRef.class).value());
     elements.add(i);
   }
 }
Example #12
0
  @Test
  public void testContainsType() {
    Collection<A> collection = new HashSet<A>();
    collection.add(new B());
    collection.add(new B());

    assertTrue(Groups.containsType(A.class, collection));
    assertTrue(Groups.containsType(B.class, collection));
    assertFalse(Groups.containsType(C.class, collection));
  }
Example #13
0
  @Test
  public void testFirstOfType() {
    Collection<A> collection = new HashSet<A>();
    collection.add(new B());
    collection.add(new B());

    assertTrue(Groups.firstOfType(C.class, collection) == null);
    assertTrue(collection.contains(Groups.firstOfType(A.class, collection)));
    assertTrue(collection.contains(Groups.firstOfType(B.class, collection)));
  }
Example #14
0
  @Test
  public void testFirstEmpty() {
    Collection<String> collection = new HashSet<String>();

    assertTrue(Groups.first(collection) == null);

    collection.add("Hello World");
    assertTrue(Groups.first(collection).equals("Hello World"));

    collection.add("Goodbye World");
    assertTrue(collection.contains(Groups.first(collection)));
  }
 /** Test of setVoters method, of class ValidatorElectionEvent. */
 @Test
 public void testSetVoters() {
   System.out.println("setVoters");
   ValidatorElectionEvent instance = new ValidatorElectionEvent();
   ValidatorVoter a = new ValidatorVoter();
   Collection<ValidatorVoter> b = new ArrayList<ValidatorVoter>();
   b.add(a);
   instance.setVoters(b);
   Collection expResult = b;
   Collection result = instance.getVoters();
   assertEquals(expResult, result);
 }
 /** Test of getCandidates method, of class ValidatorElectionEvent. */
 @Test
 public void testGetCandidates() {
   System.out.println("getCandidates");
   ValidatorElectionEvent instance = new ValidatorElectionEvent();
   ValidatorCandidate a = new ValidatorCandidate();
   Collection<ValidatorCandidate> b = new ArrayList<ValidatorCandidate>();
   b.add(a);
   instance.setCandidates(b);
   Collection expResult = b;
   Collection result = instance.getCandidates();
   assertEquals(expResult, result);
 }
  @Test
  public void testTriangle() {
    final Road[] roads = {new Road("A", "B"), new Road("B", "C"), new Road("A", "C")};

    Collection<Road> city = new HashSet<Road>();
    for (Road r : roads) {
      city.add(r);
    }
    final CityCameraPlanner cameraPlanner = new CityCameraPlanner(city);
    assertEquals(0, cameraPlanner.getCameras().size());
    assertFalse(cameraPlanner.getCameras().contains("B"));
  }
Example #18
0
 protected void assertValue(String date1, int[] date2) throws ParseException {
   Date dyndate = DynamicDate.getInstance(date1);
   int[] r = getNow(date2);
   Collection result = compare(dyndate, r);
   assertTrue(
       date1
           + "->"
           + dyndate
           + " != "
           + new Date(r[0] - 1900, r[1], r[2], r[3], r[4], r[5])
           + result,
       result.isEmpty());
 }
Example #19
0
  @Test
  public void testAddAll() throws IOException {
    final int maxItems = 13;
    final IQueue q = client.getQueue(randomString());

    Collection coll = new ArrayList(maxItems);

    for (int i = 0; i < maxItems; i++) {
      coll.add(i);
    }

    assertTrue(q.addAll(coll));
    assertEquals(coll.size(), q.size());
  }
 @Test
 public void testMultiMapValues() {
   HazelcastClient hClient = getHazelcastClient();
   MultiMap<String, String> map = hClient.getMultiMap("testMultiMapValues");
   map.put("Hello", "World");
   map.put("Hello", "Europe");
   map.put("Hello", "America");
   map.put("Hello", "Asia");
   map.put("Hello", "Africa");
   map.put("Hello", "Antarctica");
   map.put("Hello", "Australia");
   Collection<String> values = map.values();
   assertEquals(7, values.size());
 }
Example #21
0
  private void testDontPurgeAccidentaly(String k, String cfname)
      throws IOException, ExecutionException, InterruptedException {
    // This test catches the regression of CASSANDRA-2786
    Keyspace keyspace = Keyspace.open(KEYSPACE1);
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(cfname);

    // disable compaction while flushing
    cfs.clearUnsafe();
    cfs.disableAutoCompaction();

    // Add test row
    DecoratedKey key = Util.dk(k);
    RowMutation rm = new RowMutation(KEYSPACE1, key.key);
    rm.add(
        cfname,
        CompositeType.build(ByteBufferUtil.bytes("sc"), ByteBufferUtil.bytes("c")),
        ByteBufferUtil.EMPTY_BYTE_BUFFER,
        0);
    rm.apply();

    cfs.forceBlockingFlush();

    Collection<SSTableReader> sstablesBefore = cfs.getSSTables();

    QueryFilter filter = QueryFilter.getIdentityFilter(key, cfname, System.currentTimeMillis());
    assert !(cfs.getColumnFamily(filter).getColumnCount() == 0);

    // Remove key
    rm = new RowMutation(KEYSPACE1, key.key);
    rm.delete(cfname, 2);
    rm.apply();

    ColumnFamily cf = cfs.getColumnFamily(filter);
    assert cf == null || cf.getColumnCount() == 0 : "should be empty: " + cf;

    // Sleep one second so that the removal is indeed purgeable even with gcgrace == 0
    Thread.sleep(1000);

    cfs.forceBlockingFlush();

    Collection<SSTableReader> sstablesAfter = cfs.getSSTables();
    Collection<SSTableReader> toCompact = new ArrayList<SSTableReader>();
    for (SSTableReader sstable : sstablesAfter)
      if (!sstablesBefore.contains(sstable)) toCompact.add(sstable);

    Util.compact(cfs, toCompact);

    cf = cfs.getColumnFamily(filter);
    assert cf == null || cf.getColumnCount() == 0 : "should be empty: " + cf;
  }
  @Test
  public void testExample1() {
    final Road[] roads = {
      new Road("A", "B"), new Road("B", "C"), new Road("C", "D"), new Road("D", "B")
    };

    Collection<Road> city = new HashSet<Road>();
    for (Road r : roads) {
      city.add(r);
    }
    final CityCameraPlanner cameraPlanner = new CityCameraPlanner(city);
    System.out.println(cameraPlanner.getCameras());
    assertEquals(1, cameraPlanner.getCameras().size());
    assertTrue(cameraPlanner.getCameras().contains("B"));
  }
Example #23
0
  @Test
  public void testOfType() {
    Collection<A> collection = new HashSet<A>();
    collection.add(new A());
    collection.add(new B());
    collection.add(new B());
    collection.add(new A());
    collection.add(new B());
    collection.add(new A());
    collection.add(new A());
    collection.add(new C());

    assertTrue(Groups.ofType(A.class, collection).size() == 8);
    assertTrue(Groups.ofType(B.class, collection).size() == 3);
    assertTrue(Groups.ofType(C.class, collection).size() == 1);
  }
 @Test
 public void testMultiMapPutAndGet() {
   HazelcastClient hClient = getHazelcastClient();
   MultiMap<String, String> map = hClient.getMultiMap("testMultiMapPutAndGet");
   map.put("Hello", "World");
   Collection<String> values = map.get("Hello");
   assertEquals("World", values.iterator().next());
   map.put("Hello", "Europe");
   map.put("Hello", "America");
   map.put("Hello", "Asia");
   map.put("Hello", "Africa");
   map.put("Hello", "Antarctica");
   map.put("Hello", "Australia");
   values = map.get("Hello");
   assertEquals(7, values.size());
   assertTrue(map.containsKey("Hello"));
   assertFalse(map.containsKey("Hi"));
 }
 @Test
 public void get() throws InterruptedException {
   HazelcastClient hClient = getHazelcastClient();
   MultiMap<String, Integer> multiMap = hClient.getMultiMap("get");
   assertTrue(multiMap.put("a", 1));
   assertTrue(multiMap.put("a", 2));
   Map<Integer, CountDownLatch> map = new HashMap<Integer, CountDownLatch>();
   map.put(1, new CountDownLatch(1));
   map.put(2, new CountDownLatch(1));
   Collection<Integer> collection = multiMap.get("a");
   assertEquals(Values.class, collection.getClass());
   assertEquals(2, collection.size());
   for (Iterator<Integer> it = collection.iterator(); it.hasNext(); ) {
     Integer o = it.next();
     map.get(o).countDown();
   }
   assertTrue(map.get(1).await(10, TimeUnit.SECONDS));
   assertTrue(map.get(2).await(10, TimeUnit.SECONDS));
 }
  @Test
  public void testGraph() {
    final Road[] roads = {
      new Road("A", "B"), new Road("B", "C"), new Road("C", "D"), new Road("D", "B")
    };

    Collection<Road> city = new HashSet<Road>();
    for (Road r : roads) {
      city.add(r);
    }
    final CityCameraPlanner cameraPlanner = new CityCameraPlanner(city);
    Neighborhood B = cameraPlanner.getTheCity().get("B");
    cameraPlanner.resetVisited();
    assertTrue(cameraPlanner.isConnected());
    cameraPlanner.removeNeighborhood(B);
    cameraPlanner.resetVisited();
    assertFalse(cameraPlanner.isConnected());
    cameraPlanner.addNeighborhood(B);
    cameraPlanner.resetVisited();
    assertTrue(cameraPlanner.isConnected());
  }
Example #27
0
  @Test
  public void testCookie_whenCookiesArePresent() {

    final String cookieKey = "cookie1";
    final String cookieValue = "cookie1value";

    Collection<Cookie> cookies = new ArrayList<>();
    cookies.add(new Cookie(cookieKey, cookieValue));

    Cookie[] cookieArray = cookies.toArray(new Cookie[cookies.size()]);
    when(servletRequest.getCookies()).thenReturn(cookieArray);

    assertNotNull(
        "A value for the key provided should exist because a cookie with the same key is present",
        request.cookie(cookieKey));

    assertEquals(
        "The correct value for the cookie key supplied should be returned",
        cookieValue,
        request.cookie(cookieKey));
  }
Example #28
0
  @Test
  public void testUserDefinedCompaction() throws Exception {
    Keyspace keyspace = Keyspace.open(KEYSPACE1);
    final String cfname = "Standard3"; // use clean(no sstable) CF
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(cfname);

    // disable compaction while flushing
    cfs.disableAutoCompaction();

    final int ROWS_PER_SSTABLE = 10;
    for (int i = 0; i < ROWS_PER_SSTABLE; i++) {
      DecoratedKey key = Util.dk(String.valueOf(i));
      Mutation rm = new Mutation(KEYSPACE1, key.getKey());
      rm.add(
          cfname,
          Util.cellname("col"),
          ByteBufferUtil.EMPTY_BYTE_BUFFER,
          System.currentTimeMillis());
      rm.applyUnsafe();
    }
    cfs.forceBlockingFlush();
    Collection<SSTableReader> sstables = cfs.getSSTables();

    assertEquals(1, sstables.size());
    SSTableReader sstable = sstables.iterator().next();

    int prevGeneration = sstable.descriptor.generation;
    String file = new File(sstable.descriptor.filenameFor(Component.DATA)).getAbsolutePath();
    // submit user defined compaction on flushed sstable
    CompactionManager.instance.forceUserDefinedCompaction(file);
    // wait until user defined compaction finishes
    do {
      Thread.sleep(100);
    } while (CompactionManager.instance.getPendingTasks() > 0
        || CompactionManager.instance.getActiveCompactions() > 0);
    // CF should have only one sstable with generation number advanced
    sstables = cfs.getSSTables();
    assertEquals(1, sstables.size());
    assertEquals(prevGeneration + 1, sstables.iterator().next().descriptor.generation);
  }
Example #29
0
  private Map<String, List<String>> createBaseDatabaseAndTables()
      throws IOException, TajoException {

    Map<String, List<String>> createdDatabaseAndTablesMap = new HashMap<>();

    // add and divide all tables to multiple databases in a round robin manner
    for (int tableId = 0; tableId < TOTAL_TABLE_NUM; tableId++) {
      int dbIdx = tableId % DB_NUM;
      String databaseName = dbPrefix + dbIdx;

      if (!catalog.existDatabase(databaseName)) {
        catalog.createDatabase(databaseName, TajoConstants.DEFAULT_TABLESPACE_NAME);
      }

      String tableName = tablePrefix + tableId;
      TableDesc table = createMockupTable(databaseName, tableName);
      catalog.createTable(table);

      TUtil.putToNestedList(createdDatabaseAndTablesMap, databaseName, tableName);
    }

    // checking all tables for each database
    for (int dbIdx = 0; dbIdx < DB_NUM; dbIdx++) {
      String databaseName = dbPrefix + dbIdx;

      Collection<String> tableNames = catalog.getAllTableNames(databaseName);
      assertTrue(createdDatabaseAndTablesMap.containsKey(databaseName));

      assertEquals(createdDatabaseAndTablesMap.get(databaseName).size(), tableNames.size());
      for (String tableName : tableNames) {
        assertTrue(createdDatabaseAndTablesMap.get(databaseName).contains(tableName));
      }
    }

    return createdDatabaseAndTablesMap;
  }
  /** Test pending ranges and write endpoints when multiple nodes are on the move simultaneously */
  @Test
  public void testSimultaneousMove() throws UnknownHostException {
    StorageService ss = StorageService.instance;
    final int RING_SIZE = 10;
    TokenMetadata tmd = ss.getTokenMetadata();
    tmd.clearUnsafe();
    IPartitioner partitioner = RandomPartitioner.instance;
    VersionedValue.VersionedValueFactory valueFactory =
        new VersionedValue.VersionedValueFactory(partitioner);

    ArrayList<Token> endpointTokens = new ArrayList<Token>();
    ArrayList<Token> keyTokens = new ArrayList<Token>();
    List<InetAddress> hosts = new ArrayList<InetAddress>();
    List<UUID> hostIds = new ArrayList<UUID>();

    // create a ring or 10 nodes
    Util.createInitialRing(ss, partitioner, endpointTokens, keyTokens, hosts, hostIds, RING_SIZE);

    // nodes 6, 8 and 9 leave
    final int[] LEAVING = new int[] {6, 8, 9};
    for (int leaving : LEAVING)
      ss.onChange(
          hosts.get(leaving),
          ApplicationState.STATUS,
          valueFactory.leaving(Collections.singleton(endpointTokens.get(leaving))));

    // boot two new nodes with keyTokens.get(5) and keyTokens.get(7)
    InetAddress boot1 = InetAddress.getByName("127.0.1.1");
    Gossiper.instance.initializeNodeUnsafe(boot1, UUID.randomUUID(), 1);
    Gossiper.instance.injectApplicationState(
        boot1,
        ApplicationState.TOKENS,
        valueFactory.tokens(Collections.singleton(keyTokens.get(5))));
    ss.onChange(
        boot1,
        ApplicationState.STATUS,
        valueFactory.bootstrapping(Collections.<Token>singleton(keyTokens.get(5))));
    InetAddress boot2 = InetAddress.getByName("127.0.1.2");
    Gossiper.instance.initializeNodeUnsafe(boot2, UUID.randomUUID(), 1);
    Gossiper.instance.injectApplicationState(
        boot2,
        ApplicationState.TOKENS,
        valueFactory.tokens(Collections.singleton(keyTokens.get(7))));
    ss.onChange(
        boot2,
        ApplicationState.STATUS,
        valueFactory.bootstrapping(Collections.<Token>singleton(keyTokens.get(7))));

    Collection<InetAddress> endpoints = null;

    /* don't require test update every time a new keyspace is added to test/conf/cassandra.yaml */
    Map<String, AbstractReplicationStrategy> keyspaceStrategyMap =
        new HashMap<String, AbstractReplicationStrategy>();
    for (int i = 1; i <= 4; i++) {
      keyspaceStrategyMap.put(
          "LeaveAndBootstrapTestKeyspace" + i,
          getStrategy("LeaveAndBootstrapTestKeyspace" + i, tmd));
    }

    // pre-calculate the results.
    Map<String, Multimap<Token, InetAddress>> expectedEndpoints =
        new HashMap<String, Multimap<Token, InetAddress>>();
    expectedEndpoints.put(KEYSPACE1, HashMultimap.<Token, InetAddress>create());
    expectedEndpoints.get(KEYSPACE1).putAll(new BigIntegerToken("5"), makeAddrs("127.0.0.2"));
    expectedEndpoints.get(KEYSPACE1).putAll(new BigIntegerToken("15"), makeAddrs("127.0.0.3"));
    expectedEndpoints.get(KEYSPACE1).putAll(new BigIntegerToken("25"), makeAddrs("127.0.0.4"));
    expectedEndpoints.get(KEYSPACE1).putAll(new BigIntegerToken("35"), makeAddrs("127.0.0.5"));
    expectedEndpoints.get(KEYSPACE1).putAll(new BigIntegerToken("45"), makeAddrs("127.0.0.6"));
    expectedEndpoints
        .get(KEYSPACE1)
        .putAll(new BigIntegerToken("55"), makeAddrs("127.0.0.7", "127.0.0.8", "127.0.1.1"));
    expectedEndpoints.get(KEYSPACE1).putAll(new BigIntegerToken("65"), makeAddrs("127.0.0.8"));
    expectedEndpoints
        .get(KEYSPACE1)
        .putAll(new BigIntegerToken("75"), makeAddrs("127.0.0.9", "127.0.1.2", "127.0.0.1"));
    expectedEndpoints
        .get(KEYSPACE1)
        .putAll(new BigIntegerToken("85"), makeAddrs("127.0.0.10", "127.0.0.1"));
    expectedEndpoints.get(KEYSPACE1).putAll(new BigIntegerToken("95"), makeAddrs("127.0.0.1"));
    expectedEndpoints.put(KEYSPACE2, HashMultimap.<Token, InetAddress>create());
    expectedEndpoints.get(KEYSPACE2).putAll(new BigIntegerToken("5"), makeAddrs("127.0.0.2"));
    expectedEndpoints.get(KEYSPACE2).putAll(new BigIntegerToken("15"), makeAddrs("127.0.0.3"));
    expectedEndpoints.get(KEYSPACE2).putAll(new BigIntegerToken("25"), makeAddrs("127.0.0.4"));
    expectedEndpoints.get(KEYSPACE2).putAll(new BigIntegerToken("35"), makeAddrs("127.0.0.5"));
    expectedEndpoints.get(KEYSPACE2).putAll(new BigIntegerToken("45"), makeAddrs("127.0.0.6"));
    expectedEndpoints
        .get(KEYSPACE2)
        .putAll(new BigIntegerToken("55"), makeAddrs("127.0.0.7", "127.0.0.8", "127.0.1.1"));
    expectedEndpoints.get(KEYSPACE2).putAll(new BigIntegerToken("65"), makeAddrs("127.0.0.8"));
    expectedEndpoints
        .get(KEYSPACE2)
        .putAll(new BigIntegerToken("75"), makeAddrs("127.0.0.9", "127.0.1.2", "127.0.0.1"));
    expectedEndpoints
        .get(KEYSPACE2)
        .putAll(new BigIntegerToken("85"), makeAddrs("127.0.0.10", "127.0.0.1"));
    expectedEndpoints.get(KEYSPACE2).putAll(new BigIntegerToken("95"), makeAddrs("127.0.0.1"));
    expectedEndpoints.put(KEYSPACE3, HashMultimap.<Token, InetAddress>create());
    expectedEndpoints
        .get(KEYSPACE3)
        .putAll(
            new BigIntegerToken("5"),
            makeAddrs("127.0.0.2", "127.0.0.3", "127.0.0.4", "127.0.0.5", "127.0.0.6"));
    expectedEndpoints
        .get(KEYSPACE3)
        .putAll(
            new BigIntegerToken("15"),
            makeAddrs(
                "127.0.0.3",
                "127.0.0.4",
                "127.0.0.5",
                "127.0.0.6",
                "127.0.0.7",
                "127.0.1.1",
                "127.0.0.8"));
    expectedEndpoints
        .get(KEYSPACE3)
        .putAll(
            new BigIntegerToken("25"),
            makeAddrs(
                "127.0.0.4",
                "127.0.0.5",
                "127.0.0.6",
                "127.0.0.7",
                "127.0.0.8",
                "127.0.1.2",
                "127.0.0.1",
                "127.0.1.1"));
    expectedEndpoints
        .get(KEYSPACE3)
        .putAll(
            new BigIntegerToken("35"),
            makeAddrs(
                "127.0.0.5",
                "127.0.0.6",
                "127.0.0.7",
                "127.0.0.8",
                "127.0.0.9",
                "127.0.1.2",
                "127.0.0.1",
                "127.0.0.2",
                "127.0.1.1"));
    expectedEndpoints
        .get(KEYSPACE3)
        .putAll(
            new BigIntegerToken("45"),
            makeAddrs(
                "127.0.0.6",
                "127.0.0.7",
                "127.0.0.8",
                "127.0.0.9",
                "127.0.0.10",
                "127.0.1.2",
                "127.0.0.1",
                "127.0.0.2",
                "127.0.1.1",
                "127.0.0.3"));
    expectedEndpoints
        .get(KEYSPACE3)
        .putAll(
            new BigIntegerToken("55"),
            makeAddrs(
                "127.0.0.7",
                "127.0.0.8",
                "127.0.0.9",
                "127.0.0.10",
                "127.0.0.1",
                "127.0.0.2",
                "127.0.0.3",
                "127.0.0.4",
                "127.0.1.1",
                "127.0.1.2"));
    expectedEndpoints
        .get(KEYSPACE3)
        .putAll(
            new BigIntegerToken("65"),
            makeAddrs(
                "127.0.0.8",
                "127.0.0.9",
                "127.0.0.10",
                "127.0.0.1",
                "127.0.0.2",
                "127.0.1.2",
                "127.0.0.3",
                "127.0.0.4"));
    expectedEndpoints
        .get(KEYSPACE3)
        .putAll(
            new BigIntegerToken("75"),
            makeAddrs(
                "127.0.0.9",
                "127.0.0.10",
                "127.0.0.1",
                "127.0.0.2",
                "127.0.0.3",
                "127.0.1.2",
                "127.0.0.4",
                "127.0.0.5"));
    expectedEndpoints
        .get(KEYSPACE3)
        .putAll(
            new BigIntegerToken("85"),
            makeAddrs(
                "127.0.0.10", "127.0.0.1", "127.0.0.2", "127.0.0.3", "127.0.0.4", "127.0.0.5"));
    expectedEndpoints
        .get(KEYSPACE3)
        .putAll(
            new BigIntegerToken("95"),
            makeAddrs("127.0.0.1", "127.0.0.2", "127.0.0.3", "127.0.0.4", "127.0.0.5"));
    expectedEndpoints.put(KEYSPACE4, HashMultimap.<Token, InetAddress>create());
    expectedEndpoints
        .get(KEYSPACE4)
        .putAll(new BigIntegerToken("5"), makeAddrs("127.0.0.2", "127.0.0.3", "127.0.0.4"));
    expectedEndpoints
        .get(KEYSPACE4)
        .putAll(new BigIntegerToken("15"), makeAddrs("127.0.0.3", "127.0.0.4", "127.0.0.5"));
    expectedEndpoints
        .get(KEYSPACE4)
        .putAll(new BigIntegerToken("25"), makeAddrs("127.0.0.4", "127.0.0.5", "127.0.0.6"));
    expectedEndpoints
        .get(KEYSPACE4)
        .putAll(
            new BigIntegerToken("35"),
            makeAddrs("127.0.0.5", "127.0.0.6", "127.0.0.7", "127.0.1.1", "127.0.0.8"));
    expectedEndpoints
        .get(KEYSPACE4)
        .putAll(
            new BigIntegerToken("45"),
            makeAddrs(
                "127.0.0.6", "127.0.0.7", "127.0.0.8", "127.0.1.2", "127.0.0.1", "127.0.1.1"));
    expectedEndpoints
        .get(KEYSPACE4)
        .putAll(
            new BigIntegerToken("55"),
            makeAddrs(
                "127.0.0.7",
                "127.0.0.8",
                "127.0.0.9",
                "127.0.0.1",
                "127.0.0.2",
                "127.0.1.1",
                "127.0.1.2"));
    expectedEndpoints
        .get(KEYSPACE4)
        .putAll(
            new BigIntegerToken("65"),
            makeAddrs(
                "127.0.0.8", "127.0.0.9", "127.0.0.10", "127.0.1.2", "127.0.0.1", "127.0.0.2"));
    expectedEndpoints
        .get(KEYSPACE4)
        .putAll(
            new BigIntegerToken("75"),
            makeAddrs(
                "127.0.0.9", "127.0.0.10", "127.0.0.1", "127.0.1.2", "127.0.0.2", "127.0.0.3"));
    expectedEndpoints
        .get(KEYSPACE4)
        .putAll(
            new BigIntegerToken("85"),
            makeAddrs("127.0.0.10", "127.0.0.1", "127.0.0.2", "127.0.0.3"));
    expectedEndpoints
        .get(KEYSPACE4)
        .putAll(new BigIntegerToken("95"), makeAddrs("127.0.0.1", "127.0.0.2", "127.0.0.3"));

    PendingRangeCalculatorService.instance.blockUntilFinished();

    for (Map.Entry<String, AbstractReplicationStrategy> keyspaceStrategy :
        keyspaceStrategyMap.entrySet()) {
      String keyspaceName = keyspaceStrategy.getKey();
      AbstractReplicationStrategy strategy = keyspaceStrategy.getValue();

      for (int i = 0; i < keyTokens.size(); i++) {
        endpoints =
            tmd.getWriteEndpoints(
                keyTokens.get(i), keyspaceName, strategy.getNaturalEndpoints(keyTokens.get(i)));
        assertEquals(
            expectedEndpoints.get(keyspaceName).get(keyTokens.get(i)).size(), endpoints.size());
        assertTrue(
            expectedEndpoints.get(keyspaceName).get(keyTokens.get(i)).containsAll(endpoints));
      }

      // just to be sure that things still work according to the old tests, run them:
      if (strategy.getReplicationFactor() != 3) continue;
      // tokens 5, 15 and 25 should go three nodes
      for (int i = 0; i < 3; ++i) {
        endpoints =
            tmd.getWriteEndpoints(
                keyTokens.get(i), keyspaceName, strategy.getNaturalEndpoints(keyTokens.get(i)));
        assertEquals(3, endpoints.size());
        assertTrue(endpoints.contains(hosts.get(i + 1)));
        assertTrue(endpoints.contains(hosts.get(i + 2)));
        assertTrue(endpoints.contains(hosts.get(i + 3)));
      }

      // token 35 should go to nodes 4, 5, 6, 7 and boot1
      endpoints =
          tmd.getWriteEndpoints(
              keyTokens.get(3), keyspaceName, strategy.getNaturalEndpoints(keyTokens.get(3)));
      assertEquals(5, endpoints.size());
      assertTrue(endpoints.contains(hosts.get(4)));
      assertTrue(endpoints.contains(hosts.get(5)));
      assertTrue(endpoints.contains(hosts.get(6)));
      assertTrue(endpoints.contains(hosts.get(7)));
      assertTrue(endpoints.contains(boot1));

      // token 45 should go to nodes 5, 6, 7, 0, boot1 and boot2
      endpoints =
          tmd.getWriteEndpoints(
              keyTokens.get(4), keyspaceName, strategy.getNaturalEndpoints(keyTokens.get(4)));
      assertEquals(6, endpoints.size());
      assertTrue(endpoints.contains(hosts.get(5)));
      assertTrue(endpoints.contains(hosts.get(6)));
      assertTrue(endpoints.contains(hosts.get(7)));
      assertTrue(endpoints.contains(hosts.get(0)));
      assertTrue(endpoints.contains(boot1));
      assertTrue(endpoints.contains(boot2));

      // token 55 should go to nodes 6, 7, 8, 0, 1, boot1 and boot2
      endpoints =
          tmd.getWriteEndpoints(
              keyTokens.get(5), keyspaceName, strategy.getNaturalEndpoints(keyTokens.get(5)));
      assertEquals(7, endpoints.size());
      assertTrue(endpoints.contains(hosts.get(6)));
      assertTrue(endpoints.contains(hosts.get(7)));
      assertTrue(endpoints.contains(hosts.get(8)));
      assertTrue(endpoints.contains(hosts.get(0)));
      assertTrue(endpoints.contains(hosts.get(1)));
      assertTrue(endpoints.contains(boot1));
      assertTrue(endpoints.contains(boot2));

      // token 65 should go to nodes 7, 8, 9, 0, 1 and boot2
      endpoints =
          tmd.getWriteEndpoints(
              keyTokens.get(6), keyspaceName, strategy.getNaturalEndpoints(keyTokens.get(6)));
      assertEquals(6, endpoints.size());
      assertTrue(endpoints.contains(hosts.get(7)));
      assertTrue(endpoints.contains(hosts.get(8)));
      assertTrue(endpoints.contains(hosts.get(9)));
      assertTrue(endpoints.contains(hosts.get(0)));
      assertTrue(endpoints.contains(hosts.get(1)));
      assertTrue(endpoints.contains(boot2));

      // token 75 should to go nodes 8, 9, 0, 1, 2 and boot2
      endpoints =
          tmd.getWriteEndpoints(
              keyTokens.get(7), keyspaceName, strategy.getNaturalEndpoints(keyTokens.get(7)));
      assertEquals(6, endpoints.size());
      assertTrue(endpoints.contains(hosts.get(8)));
      assertTrue(endpoints.contains(hosts.get(9)));
      assertTrue(endpoints.contains(hosts.get(0)));
      assertTrue(endpoints.contains(hosts.get(1)));
      assertTrue(endpoints.contains(hosts.get(2)));
      assertTrue(endpoints.contains(boot2));

      // token 85 should go to nodes 9, 0, 1 and 2
      endpoints =
          tmd.getWriteEndpoints(
              keyTokens.get(8), keyspaceName, strategy.getNaturalEndpoints(keyTokens.get(8)));
      assertEquals(4, endpoints.size());
      assertTrue(endpoints.contains(hosts.get(9)));
      assertTrue(endpoints.contains(hosts.get(0)));
      assertTrue(endpoints.contains(hosts.get(1)));
      assertTrue(endpoints.contains(hosts.get(2)));

      // token 95 should go to nodes 0, 1 and 2
      endpoints =
          tmd.getWriteEndpoints(
              keyTokens.get(9), keyspaceName, strategy.getNaturalEndpoints(keyTokens.get(9)));
      assertEquals(3, endpoints.size());
      assertTrue(endpoints.contains(hosts.get(0)));
      assertTrue(endpoints.contains(hosts.get(1)));
      assertTrue(endpoints.contains(hosts.get(2)));
    }

    // Now finish node 6 and node 9 leaving, as well as boot1 (after this node 8 is still
    // leaving and boot2 in progress
    ss.onChange(
        hosts.get(LEAVING[0]),
        ApplicationState.STATUS,
        valueFactory.left(
            Collections.singleton(endpointTokens.get(LEAVING[0])), Gossiper.computeExpireTime()));
    ss.onChange(
        hosts.get(LEAVING[2]),
        ApplicationState.STATUS,
        valueFactory.left(
            Collections.singleton(endpointTokens.get(LEAVING[2])), Gossiper.computeExpireTime()));
    ss.onChange(
        boot1,
        ApplicationState.STATUS,
        valueFactory.normal(Collections.singleton(keyTokens.get(5))));

    // adjust precalcuated results.  this changes what the epected endpoints are.
    expectedEndpoints
        .get(KEYSPACE1)
        .get(new BigIntegerToken("55"))
        .removeAll(makeAddrs("127.0.0.7", "127.0.0.8"));
    expectedEndpoints
        .get(KEYSPACE1)
        .get(new BigIntegerToken("85"))
        .removeAll(makeAddrs("127.0.0.10"));
    expectedEndpoints
        .get(KEYSPACE2)
        .get(new BigIntegerToken("55"))
        .removeAll(makeAddrs("127.0.0.7", "127.0.0.8"));
    expectedEndpoints
        .get(KEYSPACE2)
        .get(new BigIntegerToken("85"))
        .removeAll(makeAddrs("127.0.0.10"));
    expectedEndpoints
        .get(KEYSPACE3)
        .get(new BigIntegerToken("15"))
        .removeAll(makeAddrs("127.0.0.7", "127.0.0.8"));
    expectedEndpoints
        .get(KEYSPACE3)
        .get(new BigIntegerToken("25"))
        .removeAll(makeAddrs("127.0.0.7", "127.0.1.2", "127.0.0.1"));
    expectedEndpoints
        .get(KEYSPACE3)
        .get(new BigIntegerToken("35"))
        .removeAll(makeAddrs("127.0.0.7", "127.0.0.2"));
    expectedEndpoints
        .get(KEYSPACE3)
        .get(new BigIntegerToken("45"))
        .removeAll(makeAddrs("127.0.0.7", "127.0.0.10", "127.0.0.3"));
    expectedEndpoints
        .get(KEYSPACE3)
        .get(new BigIntegerToken("55"))
        .removeAll(makeAddrs("127.0.0.7", "127.0.0.10", "127.0.0.4"));
    expectedEndpoints
        .get(KEYSPACE3)
        .get(new BigIntegerToken("65"))
        .removeAll(makeAddrs("127.0.0.10"));
    expectedEndpoints
        .get(KEYSPACE3)
        .get(new BigIntegerToken("75"))
        .removeAll(makeAddrs("127.0.0.10"));
    expectedEndpoints
        .get(KEYSPACE3)
        .get(new BigIntegerToken("85"))
        .removeAll(makeAddrs("127.0.0.10"));
    expectedEndpoints
        .get(KEYSPACE4)
        .get(new BigIntegerToken("35"))
        .removeAll(makeAddrs("127.0.0.7", "127.0.0.8"));
    expectedEndpoints
        .get(KEYSPACE4)
        .get(new BigIntegerToken("45"))
        .removeAll(makeAddrs("127.0.0.7", "127.0.1.2", "127.0.0.1"));
    expectedEndpoints
        .get(KEYSPACE4)
        .get(new BigIntegerToken("55"))
        .removeAll(makeAddrs("127.0.0.2", "127.0.0.7"));
    expectedEndpoints
        .get(KEYSPACE4)
        .get(new BigIntegerToken("65"))
        .removeAll(makeAddrs("127.0.0.10"));
    expectedEndpoints
        .get(KEYSPACE4)
        .get(new BigIntegerToken("75"))
        .removeAll(makeAddrs("127.0.0.10"));
    expectedEndpoints
        .get(KEYSPACE4)
        .get(new BigIntegerToken("85"))
        .removeAll(makeAddrs("127.0.0.10"));

    PendingRangeCalculatorService.instance.blockUntilFinished();

    for (Map.Entry<String, AbstractReplicationStrategy> keyspaceStrategy :
        keyspaceStrategyMap.entrySet()) {
      String keyspaceName = keyspaceStrategy.getKey();
      AbstractReplicationStrategy strategy = keyspaceStrategy.getValue();

      for (int i = 0; i < keyTokens.size(); i++) {
        endpoints =
            tmd.getWriteEndpoints(
                keyTokens.get(i), keyspaceName, strategy.getNaturalEndpoints(keyTokens.get(i)));
        assertEquals(
            expectedEndpoints.get(keyspaceName).get(keyTokens.get(i)).size(), endpoints.size());
        assertTrue(
            expectedEndpoints.get(keyspaceName).get(keyTokens.get(i)).containsAll(endpoints));
      }

      if (strategy.getReplicationFactor() != 3) continue;
      // leave this stuff in to guarantee the old tests work the way they were supposed to.
      // tokens 5, 15 and 25 should go three nodes
      for (int i = 0; i < 3; ++i) {
        endpoints =
            tmd.getWriteEndpoints(
                keyTokens.get(i), keyspaceName, strategy.getNaturalEndpoints(keyTokens.get(i)));
        assertEquals(3, endpoints.size());
        assertTrue(endpoints.contains(hosts.get(i + 1)));
        assertTrue(endpoints.contains(hosts.get(i + 2)));
        assertTrue(endpoints.contains(hosts.get(i + 3)));
      }

      // token 35 goes to nodes 4, 5 and boot1
      endpoints =
          tmd.getWriteEndpoints(
              keyTokens.get(3), keyspaceName, strategy.getNaturalEndpoints(keyTokens.get(3)));
      assertEquals(3, endpoints.size());
      assertTrue(endpoints.contains(hosts.get(4)));
      assertTrue(endpoints.contains(hosts.get(5)));
      assertTrue(endpoints.contains(boot1));

      // token 45 goes to nodes 5, boot1 and node7
      endpoints =
          tmd.getWriteEndpoints(
              keyTokens.get(4), keyspaceName, strategy.getNaturalEndpoints(keyTokens.get(4)));
      assertEquals(3, endpoints.size());
      assertTrue(endpoints.contains(hosts.get(5)));
      assertTrue(endpoints.contains(boot1));
      assertTrue(endpoints.contains(hosts.get(7)));

      // token 55 goes to boot1, 7, boot2, 8 and 0
      endpoints =
          tmd.getWriteEndpoints(
              keyTokens.get(5), keyspaceName, strategy.getNaturalEndpoints(keyTokens.get(5)));
      assertEquals(5, endpoints.size());
      assertTrue(endpoints.contains(boot1));
      assertTrue(endpoints.contains(hosts.get(7)));
      assertTrue(endpoints.contains(boot2));
      assertTrue(endpoints.contains(hosts.get(8)));
      assertTrue(endpoints.contains(hosts.get(0)));

      // token 65 goes to nodes 7, boot2, 8, 0 and 1
      endpoints =
          tmd.getWriteEndpoints(
              keyTokens.get(6), keyspaceName, strategy.getNaturalEndpoints(keyTokens.get(6)));
      assertEquals(5, endpoints.size());
      assertTrue(endpoints.contains(hosts.get(7)));
      assertTrue(endpoints.contains(boot2));
      assertTrue(endpoints.contains(hosts.get(8)));
      assertTrue(endpoints.contains(hosts.get(0)));
      assertTrue(endpoints.contains(hosts.get(1)));

      // token 75 goes to nodes boot2, 8, 0, 1 and 2
      endpoints =
          tmd.getWriteEndpoints(
              keyTokens.get(7), keyspaceName, strategy.getNaturalEndpoints(keyTokens.get(7)));
      assertEquals(5, endpoints.size());
      assertTrue(endpoints.contains(boot2));
      assertTrue(endpoints.contains(hosts.get(8)));
      assertTrue(endpoints.contains(hosts.get(0)));
      assertTrue(endpoints.contains(hosts.get(1)));
      assertTrue(endpoints.contains(hosts.get(2)));

      // token 85 goes to nodes 0, 1 and 2
      endpoints =
          tmd.getWriteEndpoints(
              keyTokens.get(8), keyspaceName, strategy.getNaturalEndpoints(keyTokens.get(8)));
      assertEquals(3, endpoints.size());
      assertTrue(endpoints.contains(hosts.get(0)));
      assertTrue(endpoints.contains(hosts.get(1)));
      assertTrue(endpoints.contains(hosts.get(2)));

      // token 95 goes to nodes 0, 1 and 2
      endpoints =
          tmd.getWriteEndpoints(
              keyTokens.get(9), keyspaceName, strategy.getNaturalEndpoints(keyTokens.get(9)));
      assertEquals(3, endpoints.size());
      assertTrue(endpoints.contains(hosts.get(0)));
      assertTrue(endpoints.contains(hosts.get(1)));
      assertTrue(endpoints.contains(hosts.get(2)));
    }
  }