@Test
  public void testConditioning() {
    XTandemMain main =
        new XTandemMain(
            XTandemUtilities.getResourceStream("smallSample/tandem.params"),
            "smallSample/tandem.params");
    main.loadScoringTest();
    main.loadSpectra();
    Scorer sa = main.getScoreRunner();
    IScoredScan[] conditionedScans = sa.getScans();
    final IScoredScan conditionedScan = conditionedScans[0];

    SpectrumCondition sc = sa.getSpectrumCondition();
    final IScoringAlgorithm alg = sa.getAlgorithm();
    IMeasuredSpectrum scan = alg.conditionSpectrum(conditionedScan, sc);
    Set<Integer> goodMasses = buildMassSet();

    final ISpectrumPeak[] sps = scan.getPeaks();
    for (int i = 0; i < sps.length; i++) {
      ISpectrumPeak sp = sps[i];
      validateMass(sp, peaks[2 * i], goodMasses);
      //     validatePeak(sp,peaks[2 * i],peaks[2 * i + 1]);
    }
    Assert.assertEquals(goodMasses.size(), 0);
    XTandemUtilities.breakHere();
  }
Exemplo n.º 2
0
  @Test
  public void scanTest() {
    Map<String, Map<String, ByteIterator>> keyMap = new HashMap<>();
    for (int i = 0; i < 5; i++) {
      String insertKey = KEY_PREFIX + i;
      keyMap.put(insertKey, insertRow(insertKey));
    }

    Set<String> fieldSet = new HashSet<>();
    fieldSet.add("FIELD0");
    fieldSet.add("FIELD1");
    int startIndex = 1;
    int resultRows = 3;

    Vector<HashMap<String, ByteIterator>> resultVector = new Vector<>();
    orientDBClient.scan(CLASS, KEY_PREFIX + startIndex, resultRows, fieldSet, resultVector);

    // Check the resultVector is the correct size
    assertEquals(
        "Assert the correct number of results rows were returned", resultRows, resultVector.size());
    // Check each vector row to make sure we have the correct fields
    int testIndex = startIndex;
    for (HashMap<String, ByteIterator> result : resultVector) {
      assertEquals(
          "Assert that this row has the correct number of fields", fieldSet.size(), result.size());
      for (String field : fieldSet) {
        assertEquals(
            "Assert this field is correct in this row",
            keyMap.get(KEY_PREFIX + testIndex).get(field).toString(),
            result.get(field).toString());
      }
      testIndex++;
    }
  }
Exemplo n.º 3
0
 protected ArrayList<HRegionInfo> getRegionInfoList(String tableName) throws IOException {
   Set<HRegionInfo> hRegionInfoSet = new TreeSet<>();
   try (HTable table = new HTable(conf, tableName)) {
     hRegionInfoSet.addAll(table.getRegionLocations().keySet());
   }
   return new ArrayList<>(hRegionInfoSet);
 }
Exemplo n.º 4
0
  // FIXME: fails!  needs MarcCombiningReader for mhld or at least a diff version of RawRecordReader
  @Test
  public void testMultMHLDsWithSameID() throws IOException {
    // bib134, multMhlds1
    String bibFilePath = testDataParentPath + File.separator + "mhldMergeBibs134.mrc";
    String mhldFilePath = testDataParentPath + File.separator + "mhldMergeMhlds1Mult.mrc";
    Map<String, Record> mergedRecs =
        MergeSummaryHoldings.mergeMhldsIntoBibRecordsAsMap(bibFilePath, mhldFilePath);

    Record mergedRec = mergedRecs.get("a1");
    assertEquals("Expected three 852", 3, mergedRec.getVariableFields("852").size());
    Set<String> expectedVals = new HashSet<String>();
    expectedVals.add("Location1");
    expectedVals.add("Location2");
    RecordTestingUtils.assertSubfieldHasExpectedValues(mergedRec, "852", 'b', expectedVals);

    expectedVals.clear();
    expectedVals.add("(month)");
    expectedVals.add("(season)");
    RecordTestingUtils.assertSubfieldHasExpectedValues(mergedRec, "853", 'b', expectedVals);

    assertEquals("Expected one 863", 2, mergedRec.getVariableFields("863").size());
    assertEquals("Expected one 866", 1, mergedRec.getVariableFields("866").size());
    // fail("Implement me");
    System.out.println("Test testMultMHLDsWithSameID() successful");
  }
Exemplo n.º 5
0
  @Test
  public void testJedisClusterRunsWithMultithreaded()
      throws InterruptedException, ExecutionException, IOException {
    Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
    jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379));
    final JedisCluster jc = new JedisCluster(jedisClusterNode);
    jc.set("foo", "bar");

    ThreadPoolExecutor executor =
        new ThreadPoolExecutor(10, 100, 0, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10));
    List<Future<String>> futures = new ArrayList<Future<String>>();
    for (int i = 0; i < 50; i++) {
      executor.submit(
          new Callable<String>() {
            @Override
            public String call() throws Exception {
              // FIXME : invalidate slot cache from JedisCluster to test
              // random connection also does work
              return jc.get("foo");
            }
          });
    }

    for (Future<String> future : futures) {
      String value = future.get();
      assertEquals("bar", value);
    }

    jc.close();
  }
Exemplo n.º 6
0
 /** Test of isEmpty method, of class Set. */
 @Test
 public void testIsEmpty() {
   Set<Integer> set = new Set<Integer>();
   assertTrue(set.isEmpty());
   set.addElement(0);
   assertFalse(set.isEmpty());
 }
Exemplo n.º 7
0
 /** Test of elementExists method, of class Set. */
 @Test
 public void testElementExists() {
   Set<Integer> set = new Set<Integer>();
   assertFalse(set.elementExists(1));
   set.addElement(1);
   assertTrue(set.elementExists(1));
 }
Exemplo n.º 8
0
  @Test
  public void testCloseable() throws IOException {
    Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
    jedisClusterNode.add(new HostAndPort(nodeInfo1.getHost(), nodeInfo1.getPort()));

    JedisCluster jc = null;
    try {
      jc = new JedisCluster(jedisClusterNode);
      jc.set("51", "foo");
    } finally {
      if (jc != null) {
        jc.close();
      }
    }

    Iterator<JedisPool> poolIterator = jc.getClusterNodes().values().iterator();
    while (poolIterator.hasNext()) {
      JedisPool pool = poolIterator.next();
      try {
        pool.getResource();
        fail("JedisCluster's internal pools should be already destroyed");
      } catch (JedisConnectionException e) {
        // ok to go...
      }
    }
  }
  @Test
  public void tableNameCaseDoesNotMatter() {
    JdbcContentPersistenceService.ConcurrentUpperCaseHashMap map =
        new JdbcContentPersistenceService.ConcurrentUpperCaseHashMap(10);

    map.put("lower", true);

    Assert.assertTrue(map.containsKey("lower"));
    Assert.assertTrue(map.containsKey("Lower"));
    Assert.assertTrue(map.containsKey("LOWER"));

    Assert.assertTrue(map.get("lower"));
    Assert.assertTrue(map.get("Lower"));
    Assert.assertTrue(map.get("LOWER"));

    map.putIfAbsent("UPPER", true);

    Assert.assertTrue(map.containsKey("upper"));
    Assert.assertTrue(map.containsKey("Upper"));
    Assert.assertTrue(map.containsKey("UPPER"));

    Assert.assertTrue(map.get("upper"));
    Assert.assertTrue(map.get("Upper"));
    Assert.assertTrue(map.get("UPPER"));

    Set<String> keys = map.keySet();
    Assert.assertEquals(2, keys.size());
    Assert.assertTrue(keys.contains("LOWER"));
    Assert.assertTrue(keys.contains("UPPER"));
  }
Exemplo n.º 10
0
  @Test
  public void testFlatMapMaxConcurrent() {
    final int m = 4;
    final AtomicInteger subscriptionCount = new AtomicInteger();
    Observable<Integer> source =
        Observable.range(1, 10)
            .flatMap(
                new Func1<Integer, Observable<Integer>>() {
                  @Override
                  public Observable<Integer> call(Integer t1) {
                    return compose(Observable.range(t1 * 10, 2), subscriptionCount, m)
                        .subscribeOn(Schedulers.computation());
                  }
                },
                m);

    TestSubscriber<Integer> ts = new TestSubscriber<Integer>();

    source.subscribe(ts);

    ts.awaitTerminalEvent();
    ts.assertNoErrors();
    Set<Integer> expected =
        new HashSet<Integer>(
            Arrays.asList(
                10, 11, 20, 21, 30, 31, 40, 41, 50, 51, 60, 61, 70, 71, 80, 81, 90, 91, 100, 101));
    Assert.assertEquals(expected.size(), ts.getOnNextEvents().size());
    Assert.assertTrue(expected.containsAll(ts.getOnNextEvents()));
  }
Exemplo n.º 11
0
  private List<String> executeDDL(
      String ddlFileName,
      @Nullable String dataFileName,
      boolean isLocalTable,
      @Nullable String[] args)
      throws Exception {

    Path ddlFilePath = new Path(currentQueryPath, ddlFileName);
    FileSystem fs = ddlFilePath.getFileSystem(conf);
    assertTrue(ddlFilePath + " existence check", fs.exists(ddlFilePath));

    String template = FileUtil.readTextFile(new File(ddlFilePath.toUri()));
    String dataFilePath = null;
    if (dataFileName != null) {
      dataFilePath = getDataSetFile(dataFileName).toString();
    }
    String compiled = compileTemplate(template, dataFilePath, args);

    List<ParsedResult> parsedResults = SimpleParser.parseScript(compiled);
    List<String> createdTableNames = new ArrayList<String>();

    for (ParsedResult parsedResult : parsedResults) {
      // parse a statement
      Expr expr = sqlParser.parse(parsedResult.getStatement());
      assertNotNull(ddlFilePath + " cannot be parsed", expr);

      if (expr.getType() == OpType.CreateTable) {
        CreateTable createTable = (CreateTable) expr;
        String tableName = createTable.getTableName();
        assertTrue("Table creation is failed.", client.updateQuery(parsedResult.getStatement()));
        TableDesc createdTable = client.getTableDesc(tableName);
        String createdTableName = createdTable.getName();

        assertTrue(
            "table '" + createdTableName + "' creation check", client.existTable(createdTableName));
        if (isLocalTable) {
          createdTableGlobalSet.add(createdTableName);
          createdTableNames.add(tableName);
        }
      } else if (expr.getType() == OpType.DropTable) {
        DropTable dropTable = (DropTable) expr;
        String tableName = dropTable.getTableName();
        assertTrue(
            "table '" + tableName + "' existence check",
            client.existTable(CatalogUtil.buildFQName(currentDatabase, tableName)));
        assertTrue("table drop is failed.", client.updateQuery(parsedResult.getStatement()));
        assertFalse(
            "table '" + tableName + "' dropped check",
            client.existTable(CatalogUtil.buildFQName(currentDatabase, tableName)));
        if (isLocalTable) {
          createdTableGlobalSet.remove(tableName);
        }
      } else {
        assertTrue(ddlFilePath + " is not a Create or Drop Table statement", false);
      }
    }

    return createdTableNames;
  }
  /**
   * these are the masses XTandem has
   *
   * @return
   */
  public static Set<Integer> buildMassSet() {
    Set<Integer> holder = new HashSet<Integer>();
    for (int i = 0; i < peaks.length; i += 2) {
      holder.add(asInt(peaks[i]));
    }

    return holder;
  }
  @Test
  public void testHash() {
    Set<Integer> set = new HashSet<Integer>();
    for (WordNgram w : myNgrams) {
      set.add(w.hashCode());
    }

    assertTrue("hash code test", set.size() > 8);
  }
Exemplo n.º 14
0
 /** Test of addElement method, of class Set. */
 @Test
 public void testAddElement() {
   Set<String> set = new Set<String>();
   set.addElement("m");
   set.addElement("h");
   set.addElement("m");
   assertTrue(set.elementExists("m"));
   assertFalse(set.elementExists("n"));
 }
Exemplo n.º 15
0
 /** Test of deleteElement method, of class Set. */
 @Test(expected = ElementNotFoundException.class)
 public void testDeleteElement() throws Exception {
   Set<Integer> set = new Set<Integer>();
   set.deleteElement(3);
   set.addElement(1);
   set.addElement(4);
   set.deleteElement(1);
   assertFalse(set.elementExists(1));
 }
Exemplo n.º 16
0
 @Test(expected = JedisClusterMaxRedirectionsException.class)
 public void testRedisClusterMaxRedirections() {
   Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
   jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379));
   JedisCluster jc = new JedisCluster(jedisClusterNode);
   int slot51 = JedisClusterCRC16.getSlot("51");
   // This will cause an infinite redirection loop
   node2.clusterSetSlotMigrating(slot51, JedisClusterTestUtil.getNodeId(node3.clusterNodes()));
   jc.set("51", "foo");
 }
Exemplo n.º 17
0
 @Test(expected = JedisConnectionException.class)
 public void testIfPoolConfigAppliesToClusterPools() {
   GenericObjectPoolConfig config = new GenericObjectPoolConfig();
   config.setMaxTotal(0);
   config.setMaxWaitMillis(2000);
   Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
   jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379));
   JedisCluster jc = new JedisCluster(jedisClusterNode, config);
   jc.set("52", "poolTestValue");
 }
Exemplo n.º 18
0
  @Test
  public void testDiscoverNodesAutomatically() {
    Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
    jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379));
    JedisCluster jc = new JedisCluster(jedisClusterNode);
    assertEquals(3, jc.getClusterNodes().size());

    JedisCluster jc2 = new JedisCluster(new HostAndPort("127.0.0.1", 7379));
    assertEquals(3, jc2.getClusterNodes().size());
  }
Exemplo n.º 19
0
 @Test
 public void testAskResponse() throws InterruptedException {
   Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
   jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379));
   JedisCluster jc = new JedisCluster(jedisClusterNode);
   int slot51 = JedisClusterCRC16.getSlot("51");
   node3.clusterSetSlotImporting(slot51, JedisClusterTestUtil.getNodeId(node2.clusterNodes()));
   node2.clusterSetSlotMigrating(slot51, JedisClusterTestUtil.getNodeId(node3.clusterNodes()));
   jc.set("51", "foo");
   assertEquals("foo", jc.get("51"));
 }
  @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.º 21
0
  @Test(expected = JedisClusterMaxRedirectionsException.class, timeout = 2000)
  public void testReturnConnectionOnRedirection() {
    Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
    jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379));
    JedisPoolConfig config = new JedisPoolConfig();
    config.setMaxTotal(1);
    JedisCluster jc = new JedisCluster(jedisClusterNode, 0, 2, config);

    // This will cause an infinite redirection between node 2 and 3
    node3.clusterSetSlotMigrating(15363, JedisClusterTestUtil.getNodeId(node2.clusterNodes()));
    jc.get("e");
  }
Exemplo n.º 22
0
  @Test
  public void testMigrateToNewNode() throws InterruptedException {
    log.info("test migrate slot to new node");
    Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
    jedisClusterNode.add(nodeInfo1);
    JedisCluster jc = new JedisCluster(jedisClusterNode);
    node4.clusterMeet(localHost, nodeInfo1.getPort());

    String node3Id = JedisClusterTestUtil.getNodeId(node3.clusterNodes());
    String node4Id = JedisClusterTestUtil.getNodeId(node4.clusterNodes());
    JedisClusterTestUtil.waitForClusterReady(node4);
    node3.clusterSetSlotMigrating(15363, node4Id);
    node4.clusterSetSlotImporting(15363, node3Id);
    try {
      node4.set("e", "e");
    } catch (JedisMovedDataException jme) {
      assertEquals(15363, jme.getSlot());
      assertEquals(new HostAndPort(localHost, nodeInfo3.getPort()), jme.getTargetNode());
    }

    try {
      node3.set("e", "e");
    } catch (JedisAskDataException jae) {
      assertEquals(15363, jae.getSlot());
      assertEquals(new HostAndPort(localHost, nodeInfo4.getPort()), jae.getTargetNode());
    }

    jc.set("e", "e");

    try {
      node4.get("e");
    } catch (JedisMovedDataException jme) {
      assertEquals(15363, jme.getSlot());
      assertEquals(new HostAndPort(localHost, nodeInfo3.getPort()), jme.getTargetNode());
    }
    try {
      node3.get("e");
    } catch (JedisAskDataException jae) {
      assertEquals(15363, jae.getSlot());
      assertEquals(new HostAndPort(localHost, nodeInfo4.getPort()), jae.getTargetNode());
    }

    assertEquals("e", jc.get("e"));

    node4.clusterSetSlotNode(15363, node4Id);
    node3.clusterSetSlotNode(15363, node4Id);
    // assertEquals("e", jc.get("e"));
    assertEquals("e", node4.get("e"));

    // assertEquals("e", node3.get("e"));

  }
  @Test
  public void testRemoveService() {
    ServiceHolder tested = new ServiceHolder();
    Object service = new Object();

    // Get the hash set.
    Set<Object> servicesSet = getField(tested, Set.class);
    servicesSet.add(service);

    tested.removeService(service);

    assertTrue("Set should be empty after removeal.", servicesSet.isEmpty());
  }
  public static Set<BigInteger> createPrimesSet(int max) {
    Set<BigInteger> primes = new HashSet<BigInteger>();
    BigInteger n = new BigInteger("2");
    BigInteger maxValue = new BigInteger(String.valueOf(max));

    while (n.compareTo(maxValue) < 0) {
      primes.add(n);
      n = n.nextProbablePrime();
    }

    System.out.println("Primes under " + max + " generated.");
    return primes;
  }
Exemplo n.º 25
0
  @Test
  public void testClusterCountKeysInSlot() {
    Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
    jedisClusterNode.add(new HostAndPort(nodeInfo1.getHost(), nodeInfo1.getPort()));
    JedisCluster jc = new JedisCluster(jedisClusterNode);

    for (int index = 0; index < 5; index++) {
      jc.set("foo{bar}" + index, "hello");
    }

    int slot = JedisClusterCRC16.getSlot("foo{bar}");
    assertEquals(5, node1.clusterCountKeysInSlot(slot).intValue());
  }
Exemplo n.º 26
0
  @Test
  public void testJedisClusterTimeout() {
    Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
    jedisClusterNode.add(new HostAndPort(nodeInfo1.getHost(), nodeInfo1.getPort()));

    JedisCluster jc = new JedisCluster(jedisClusterNode, 4000);

    for (JedisPool pool : jc.getClusterNodes().values()) {
      Jedis jedis = pool.getResource();
      assertEquals(jedis.getClient().getConnectionTimeout(), 4000);
      assertEquals(jedis.getClient().getSoTimeout(), 4000);
      jedis.close();
    }
  }
Exemplo n.º 27
0
  @Test
  public void testRecalculateSlotsWhenMoved() throws InterruptedException {
    Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
    jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379));
    JedisCluster jc = new JedisCluster(jedisClusterNode);
    int slot51 = JedisClusterCRC16.getSlot("51");
    node2.clusterDelSlots(slot51);
    node3.clusterDelSlots(slot51);
    node3.clusterAddSlots(slot51);

    JedisClusterTestUtil.waitForClusterReady(node1, node2, node3);
    jc.set("51", "foo");
    assertEquals("foo", jc.get("51"));
  }
Exemplo n.º 28
0
  /** slot->nodes 15363 node3 e */
  @Test
  public void testMigrate() {
    log.info("test migrate slot");
    Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
    jedisClusterNode.add(nodeInfo1);
    JedisCluster jc = new JedisCluster(jedisClusterNode);
    String node3Id = JedisClusterTestUtil.getNodeId(node3.clusterNodes());
    String node2Id = JedisClusterTestUtil.getNodeId(node2.clusterNodes());
    node3.clusterSetSlotMigrating(15363, node2Id);
    node2.clusterSetSlotImporting(15363, node3Id);
    try {
      node2.set("e", "e");
    } catch (JedisMovedDataException jme) {
      assertEquals(15363, jme.getSlot());
      assertEquals(new HostAndPort(localHost, nodeInfo3.getPort()), jme.getTargetNode());
    }

    try {
      node3.set("e", "e");
    } catch (JedisAskDataException jae) {
      assertEquals(15363, jae.getSlot());
      assertEquals(new HostAndPort(localHost, nodeInfo2.getPort()), jae.getTargetNode());
    }

    jc.set("e", "e");

    try {
      node2.get("e");
    } catch (JedisMovedDataException jme) {
      assertEquals(15363, jme.getSlot());
      assertEquals(new HostAndPort(localHost, nodeInfo3.getPort()), jme.getTargetNode());
    }
    try {
      node3.get("e");
    } catch (JedisAskDataException jae) {
      assertEquals(15363, jae.getSlot());
      assertEquals(new HostAndPort(localHost, nodeInfo2.getPort()), jae.getTargetNode());
    }

    assertEquals("e", jc.get("e"));

    node2.clusterSetSlotNode(15363, node2Id);
    node3.clusterSetSlotNode(15363, node2Id);
    // assertEquals("e", jc.get("e"));
    assertEquals("e", node2.get("e"));

    // assertEquals("e", node3.get("e"));

  }
Exemplo n.º 29
0
  @Test(timeout = 2000)
  public void testReturnConnectionOnJedisConnectionException() throws InterruptedException {
    Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
    jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379));
    JedisPoolConfig config = new JedisPoolConfig();
    config.setMaxTotal(1);
    JedisCluster jc = new JedisCluster(jedisClusterNode, config);

    Jedis j = jc.getClusterNodes().get("127.0.0.1:7380").getResource();
    ClientKillerUtil.tagClient(j, "DEAD");
    ClientKillerUtil.killClient(j, "DEAD");
    j.close();

    jc.get("test");
  }
 private void checkValue(
     List<BusinessObject.Value> boValues, boolean strict, String name, Object... values) {
   Set<Object> expected = CollectionUtils.newSetFromIterator(Arrays.asList(values).iterator());
   Set<Object> actual = CollectionUtils.newSet();
   for (BusinessObject.Value boValue : boValues) {
     Map<?, ?> data = (Map<?, ?>) boValue.getValue();
     actual.add(data.get(name));
   }
   if (strict) {
     Assert.assertEquals("Values: ", expected, actual);
   } else {
     expected.removeAll(actual);
     Assert.assertTrue("Missing values: " + expected, expected.isEmpty());
   }
 }