Exemplo n.º 1
0
  @Test
  public void testCreateAndDropTable() throws Exception {
    catalog.createDatabase("tmpdb1", TajoConstants.DEFAULT_TABLESPACE_NAME);
    assertTrue(catalog.existDatabase("tmpdb1"));
    catalog.createDatabase("tmpdb2", TajoConstants.DEFAULT_TABLESPACE_NAME);
    assertTrue(catalog.existDatabase("tmpdb2"));

    TableDesc table1 = createMockupTable("tmpdb1", "table1");
    catalog.createTable(table1);

    TableDesc table2 = createMockupTable("tmpdb2", "table2");
    catalog.createTable(table2);

    Set<String> tmpdb1 = Sets.newHashSet(catalog.getAllTableNames("tmpdb1"));
    assertEquals(1, tmpdb1.size());
    assertTrue(tmpdb1.contains("table1"));

    Set<String> tmpdb2 = Sets.newHashSet(catalog.getAllTableNames("tmpdb2"));
    assertEquals(1, tmpdb2.size());
    assertTrue(tmpdb2.contains("table2"));

    catalog.dropDatabase("tmpdb1");
    assertFalse(catalog.existDatabase("tmpdb1"));

    tmpdb2 = Sets.newHashSet(catalog.getAllTableNames("tmpdb2"));
    assertEquals(1, tmpdb2.size());
    assertTrue(tmpdb2.contains("table2"));

    catalog.dropDatabase("tmpdb2");
    assertFalse(catalog.existDatabase("tmpdb2"));
  }
Exemplo n.º 2
0
  public void checkSlice(
      String[][] values, Set<KeyColumn> removed, int key, int start, int end, int limit) {
    List<Entry> entries;
    if (limit <= 0)
      entries =
          store.getSlice(
              KeyValueStoreUtil.getBuffer(key),
              KeyValueStoreUtil.getBuffer(start),
              KeyValueStoreUtil.getBuffer(end),
              tx);
    else
      entries =
          store.getSlice(
              KeyValueStoreUtil.getBuffer(key),
              KeyValueStoreUtil.getBuffer(start),
              KeyValueStoreUtil.getBuffer(end),
              limit,
              tx);

    int pos = 0;
    for (int i = start; i < end; i++) {
      if (removed.contains(new KeyColumn(key, i))) continue;
      if (limit <= 0 || pos < limit) {
        Entry entry = entries.get(pos);
        int col = KeyValueStoreUtil.getID(entry.getColumn());
        String str = KeyValueStoreUtil.getString(entry.getValue());
        assertEquals(i, col);
        assertEquals(values[key][i], str);
      }
      pos++;
    }
    assertNotNull(entries);
    if (limit > 0 && pos > limit) assertEquals(limit, entries.size());
    else assertEquals(pos, entries.size());
  }
Exemplo n.º 3
0
  /**
   * Тестирование на коллекции HashSet
   *
   * @throws Exception
   */
  @Test
  public void testOnHashSet() throws Exception {
    Set<UserHashcode> users = new HashSet<>();
    users.add(user1);
    assertTrue(users.contains(user1));

    // user3 копия user1 но не содержится в Set. Поиск идет по equals, а он не переопределен
    assertFalse(users.contains(user3));

    users.add(user2);
    users.add(user3);

    // user3 не перезатирает user1, т.к. не только должны совпадать hashCode, но и equals
    // Совпадение hashCode не гарантирует равенство equals, поэтому и нет перезатирания
    assertEquals(3, users.size());
  }
 @Test
 public void iterateOverMapEntries() {
   HazelcastClient hClient = getHazelcastClient();
   IMap<String, String> map = hClient.getMap("iterateOverMapEntries");
   map.put("1", "A");
   map.put("2", "B");
   map.put("3", "C");
   Set<Entry<String, String>> entrySet = map.entrySet();
   assertEquals(3, entrySet.size());
   Set<String> keySet = map.keySet();
   for (Entry<String, String> entry : entrySet) {
     assertTrue(keySet.contains(entry.getKey()));
     assertEquals(entry.getValue(), map.get(entry.getKey()));
   }
   Iterator<Entry<String, String>> it = entrySet.iterator();
   for (String key : keySet) {
     MapEntry mapEntry = map.getMapEntry(key);
     assertEquals(1, mapEntry.getHits());
   }
   while (it.hasNext()) {
     it.next();
     it.remove();
   }
   assertTrue(map.isEmpty());
 }
Exemplo n.º 5
0
 public void workerSetTest() {
   Set<Worker> workerSet = new HashSet<Worker>();
   Worker worker1 = new Worker("张三", 18);
   worker1.setWorkerId(1);
   workerSet.add(worker1);
   Worker worker2 = new Worker("李四", 8);
   worker2.setWorkerId(2);
   System.out.println(workerSet.contains(worker2));
 }
Exemplo n.º 6
0
 public void checkKeys(Set<Integer> removed) {
   for (int i = 0; i < numKeys; i++) {
     if (removed.contains(i)) {
       assertFalse(store.containsKey(KeyValueStoreUtil.getBuffer(i), tx));
     } else {
       assertTrue(store.containsKey(KeyValueStoreUtil.getBuffer(i), tx));
     }
   }
 }
  @Test
  public void userServiceReturnsExpectedData() throws Exception {
    setContext(
        "<ldap-user-service id='ldapUDS' user-search-filter='(uid={0})' group-search-filter='member={0}' /><ldap-server ldif='classpath:test-server.ldif'/>");

    UserDetailsService uds = (UserDetailsService) appCtx.getBean("ldapUDS");
    UserDetails ben = uds.loadUserByUsername("ben");

    Set<String> authorities = AuthorityUtils.authorityListToSet(ben.getAuthorities());
    assertEquals(3, authorities.size());
    assertTrue(authorities.contains("ROLE_DEVELOPERS"));
  }
Exemplo n.º 8
0
  @Test
  public void testClonesClassnames() {
    Document doc = Jsoup.parse("<div class='one two'></div>");
    Element div = doc.select("div").first();
    Set<String> classes = div.classNames();
    assertEquals(2, classes.size());
    assertTrue(classes.contains("one"));
    assertTrue(classes.contains("two"));

    Element copy = div.clone();
    Set<String> copyClasses = copy.classNames();
    assertEquals(2, copyClasses.size());
    assertTrue(copyClasses.contains("one"));
    assertTrue(copyClasses.contains("two"));
    copyClasses.add("three");
    copyClasses.remove("one");

    assertTrue(classes.contains("one"));
    assertFalse(classes.contains("three"));
    assertFalse(copyClasses.contains("one"));
    assertTrue(copyClasses.contains("three"));

    assertEquals("", div.html());
    assertEquals("", copy.html());
  }
Exemplo n.º 9
0
 public void checkValues(String[][] values, Set<KeyColumn> removed) {
   for (int i = 0; i < numKeys; i++) {
     for (int j = 0; j < numColumns; j++) {
       ByteBuffer result =
           store.get(KeyValueStoreUtil.getBuffer(i), KeyValueStoreUtil.getBuffer(j), tx);
       if (removed.contains(new KeyColumn(i, j))) {
         assertNull(result);
       } else {
         Assert.assertEquals(values[i][j], KeyValueStoreUtil.getString(result));
       }
     }
   }
 }
Exemplo n.º 10
0
 public void checkValueExistence(String[][] values, Set<KeyColumn> removed) {
   for (int i = 0; i < numKeys; i++) {
     for (int j = 0; j < numColumns; j++) {
       boolean result =
           store.containsKeyColumn(
               KeyValueStoreUtil.getBuffer(i), KeyValueStoreUtil.getBuffer(j), tx);
       if (removed.contains(new KeyColumn(i, j))) {
         assertFalse(result);
       } else {
         assertTrue(result);
       }
     }
   }
 }
Exemplo n.º 11
0
  @Test
  public void testClassDomMethods() {
    Document doc =
        Jsoup.parse("<div><span class=' mellow yellow '>Hello <b>Yellow</b></span></div>");
    List<Element> els = doc.getElementsByAttribute("class");
    Element span = els.get(0);
    assertEquals("mellow yellow", span.className());
    assertTrue(span.hasClass("mellow"));
    assertTrue(span.hasClass("yellow"));
    Set<String> classes = span.classNames();
    assertEquals(2, classes.size());
    assertTrue(classes.contains("mellow"));
    assertTrue(classes.contains("yellow"));

    assertEquals("", doc.className());
    classes = doc.classNames();
    assertEquals(0, classes.size());
    assertFalse(doc.hasClass("mellow"));
  }
Exemplo n.º 12
0
  @Test(timeout = 30000)
  public void flatMapRangeMixedAsyncLoop() {
    for (int i = 0; i < 2000; i++) {
      if (i % 10 == 0) {
        System.out.println("flatMapRangeAsyncLoop > " + i);
      }
      TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
      Observable.range(0, 1000)
          .flatMap(
              new Func1<Integer, Observable<Integer>>() {
                final Random rnd = new Random();

                @Override
                public Observable<Integer> call(Integer t) {
                  Observable<Integer> r = Observable.just(t);
                  if (rnd.nextBoolean()) {
                    r = r.asObservable();
                  }
                  return r;
                }
              })
          .observeOn(Schedulers.computation())
          .subscribe(ts);

      ts.awaitTerminalEvent(2500, TimeUnit.MILLISECONDS);
      if (ts.getOnCompletedEvents().isEmpty()) {
        System.out.println(ts.getOnNextEvents().size());
      }
      ts.assertTerminalEvent();
      ts.assertNoErrors();
      List<Integer> list = ts.getOnNextEvents();
      if (list.size() < 1000) {
        Set<Integer> set = new HashSet<Integer>(list);
        for (int j = 0; j < 1000; j++) {
          if (!set.contains(j)) {
            System.out.println(j + " missing");
          }
        }
      }
      assertEquals(1000, list.size());
    }
  }
Exemplo n.º 13
0
  @Test
  public void testAddAndDelIndex() throws Exception {
    TableDesc desc = prepareTable();
    prepareIndexDescs();
    catalog.createTable(desc);

    assertFalse(catalog.existIndexByName(DEFAULT_DATABASE_NAME, desc1.getName()));
    assertFalse(
        catalog.existIndexByColumnNames(DEFAULT_DATABASE_NAME, "indexed", new String[] {"id"}));
    catalog.createIndex(desc1);
    assertTrue(catalog.existIndexByName(DEFAULT_DATABASE_NAME, desc1.getName()));
    assertTrue(
        catalog.existIndexByColumnNames(DEFAULT_DATABASE_NAME, "indexed", new String[] {"id"}));

    assertFalse(catalog.existIndexByName(DEFAULT_DATABASE_NAME, desc2.getName()));
    assertFalse(
        catalog.existIndexByColumnNames(DEFAULT_DATABASE_NAME, "indexed", new String[] {"score"}));
    catalog.createIndex(desc2);
    assertTrue(catalog.existIndexByName(DEFAULT_DATABASE_NAME, desc2.getName()));
    assertTrue(
        catalog.existIndexByColumnNames(DEFAULT_DATABASE_NAME, "indexed", new String[] {"score"}));

    Set<IndexDesc> indexDescs = new HashSet<>();
    indexDescs.add(desc1);
    indexDescs.add(desc2);
    indexDescs.add(desc3);
    for (IndexDesc index : catalog.getAllIndexesByTable(DEFAULT_DATABASE_NAME, "indexed")) {
      assertTrue(indexDescs.contains(index));
    }

    catalog.dropIndex(DEFAULT_DATABASE_NAME, desc1.getName());
    assertFalse(catalog.existIndexByName(DEFAULT_DATABASE_NAME, desc1.getName()));
    catalog.dropIndex(DEFAULT_DATABASE_NAME, desc2.getName());
    assertFalse(catalog.existIndexByName(DEFAULT_DATABASE_NAME, desc2.getName()));

    catalog.dropTable(desc.getName());
    assertFalse(catalog.existsTable(desc.getName()));
  }