コード例 #1
0
ファイル: JavaDatasetSuite.java プロジェクト: pallavipr/spark
  @Test
  public void testNestedTupleEncoder() {
    // test ((int, string), string)
    Encoder<Tuple2<Tuple2<Integer, String>, String>> encoder =
        Encoders.tuple(Encoders.tuple(Encoders.INT(), Encoders.STRING()), Encoders.STRING());
    List<Tuple2<Tuple2<Integer, String>, String>> data =
        Arrays.asList(tuple2(tuple2(1, "a"), "a"), tuple2(tuple2(2, "b"), "b"));
    Dataset<Tuple2<Tuple2<Integer, String>, String>> ds = context.createDataset(data, encoder);
    Assert.assertEquals(data, ds.collectAsList());

    // test (int, (string, string, long))
    Encoder<Tuple2<Integer, Tuple3<String, String, Long>>> encoder2 =
        Encoders.tuple(
            Encoders.INT(), Encoders.tuple(Encoders.STRING(), Encoders.STRING(), Encoders.LONG()));
    List<Tuple2<Integer, Tuple3<String, String, Long>>> data2 =
        Arrays.asList(tuple2(1, new Tuple3<String, String, Long>("a", "b", 3L)));
    Dataset<Tuple2<Integer, Tuple3<String, String, Long>>> ds2 =
        context.createDataset(data2, encoder2);
    Assert.assertEquals(data2, ds2.collectAsList());

    // test (int, ((string, long), string))
    Encoder<Tuple2<Integer, Tuple2<Tuple2<String, Long>, String>>> encoder3 =
        Encoders.tuple(
            Encoders.INT(),
            Encoders.tuple(Encoders.tuple(Encoders.STRING(), Encoders.LONG()), Encoders.STRING()));
    List<Tuple2<Integer, Tuple2<Tuple2<String, Long>, String>>> data3 =
        Arrays.asList(tuple2(1, tuple2(tuple2("a", 2L), "b")));
    Dataset<Tuple2<Integer, Tuple2<Tuple2<String, Long>, String>>> ds3 =
        context.createDataset(data3, encoder3);
    Assert.assertEquals(data3, ds3.collectAsList());
  }
コード例 #2
0
ファイル: JavaDatasetSuite.java プロジェクト: pallavipr/spark
  @Test
  public void testTypedAggregation() {
    Encoder<Tuple2<String, Integer>> encoder = Encoders.tuple(Encoders.STRING(), Encoders.INT());
    List<Tuple2<String, Integer>> data =
        Arrays.asList(tuple2("a", 1), tuple2("a", 2), tuple2("b", 3));
    Dataset<Tuple2<String, Integer>> ds = context.createDataset(data, encoder);

    GroupedDataset<String, Tuple2<String, Integer>> grouped =
        ds.groupBy(
            new MapFunction<Tuple2<String, Integer>, String>() {
              @Override
              public String call(Tuple2<String, Integer> value) throws Exception {
                return value._1();
              }
            },
            Encoders.STRING());

    Dataset<Tuple2<String, Integer>> agged =
        grouped.agg(new IntSumOf().toColumn(Encoders.INT(), Encoders.INT()));
    Assert.assertEquals(Arrays.asList(tuple2("a", 3), tuple2("b", 3)), agged.collectAsList());

    Dataset<Tuple2<String, Integer>> agged2 =
        grouped
            .agg(new IntSumOf().toColumn(Encoders.INT(), Encoders.INT()))
            .as(Encoders.tuple(Encoders.STRING(), Encoders.INT()));
    Assert.assertEquals(
        Arrays.asList(new Tuple2<>("a", 3), new Tuple2<>("b", 3)), agged2.collectAsList());
  }
コード例 #3
0
ファイル: JavaDatasetSuite.java プロジェクト: pallavipr/spark
  @Test
  public void testTupleEncoder() {
    Encoder<Tuple2<Integer, String>> encoder2 = Encoders.tuple(Encoders.INT(), Encoders.STRING());
    List<Tuple2<Integer, String>> data2 = Arrays.asList(tuple2(1, "a"), tuple2(2, "b"));
    Dataset<Tuple2<Integer, String>> ds2 = context.createDataset(data2, encoder2);
    Assert.assertEquals(data2, ds2.collectAsList());

    Encoder<Tuple3<Integer, Long, String>> encoder3 =
        Encoders.tuple(Encoders.INT(), Encoders.LONG(), Encoders.STRING());
    List<Tuple3<Integer, Long, String>> data3 =
        Arrays.asList(new Tuple3<Integer, Long, String>(1, 2L, "a"));
    Dataset<Tuple3<Integer, Long, String>> ds3 = context.createDataset(data3, encoder3);
    Assert.assertEquals(data3, ds3.collectAsList());

    Encoder<Tuple4<Integer, String, Long, String>> encoder4 =
        Encoders.tuple(Encoders.INT(), Encoders.STRING(), Encoders.LONG(), Encoders.STRING());
    List<Tuple4<Integer, String, Long, String>> data4 =
        Arrays.asList(new Tuple4<Integer, String, Long, String>(1, "b", 2L, "a"));
    Dataset<Tuple4<Integer, String, Long, String>> ds4 = context.createDataset(data4, encoder4);
    Assert.assertEquals(data4, ds4.collectAsList());

    Encoder<Tuple5<Integer, String, Long, String, Boolean>> encoder5 =
        Encoders.tuple(
            Encoders.INT(),
            Encoders.STRING(),
            Encoders.LONG(),
            Encoders.STRING(),
            Encoders.BOOLEAN());
    List<Tuple5<Integer, String, Long, String, Boolean>> data5 =
        Arrays.asList(new Tuple5<Integer, String, Long, String, Boolean>(1, "b", 2L, "a", true));
    Dataset<Tuple5<Integer, String, Long, String, Boolean>> ds5 =
        context.createDataset(data5, encoder5);
    Assert.assertEquals(data5, ds5.collectAsList());
  }
コード例 #4
0
  /**
   * Create business object instances via API (not via process instances) and validate if they're
   * created and if a business object query for a given primary key returns the corresponding BO.
   */
  @Test
  public void CreateCustomersCheck() {
    DeployedModelDescription model =
        sf.getQueryService().getModels(DeployedModelQuery.findActiveForId(MODEL_NAME2)).get(0);
    for (int i = 1; i <= 3; i++) {
      createCustomer(model, i);
    }

    String businessObjectQualifiedId = new QName(model.getId(), "Customer").toString();
    BusinessObjectQuery query =
        BusinessObjectQuery.findForBusinessObject(businessObjectQualifiedId);
    query.setPolicy(new BusinessObjectQuery.Policy(BusinessObjectQuery.Option.WITH_VALUES));
    BusinessObjects bos = sf.getQueryService().getAllBusinessObjects(query);
    Assert.assertEquals("Objects", 1, bos.getSize());
    BusinessObject bo = bos.get(0);
    List<BusinessObject.Value> values = bo.getValues();
    Assert.assertEquals("Values", 3, values.size());

    query = BusinessObjectQuery.findWithPrimaryKey(businessObjectQualifiedId, 2);
    query.setPolicy(new BusinessObjectQuery.Policy(BusinessObjectQuery.Option.WITH_VALUES));
    bos = sf.getQueryService().getAllBusinessObjects(query);
    Assert.assertEquals("Objects", 1, bos.getSize());
    bo = bos.get(0);
    values = bo.getValues();
    Assert.assertEquals("Values", 1, values.size());
    checkValue(values, true, "firstName", "Danny2");
  }
コード例 #5
0
  @Before
  public void setup() {
    for (int customerId = 1; customerId <= 5; customerId++) {
      ProcessInstance pi =
          sf.getWorkflowService()
              .startProcess(new QName(MODEL_NAME2, "OrderCreation").toString(), null, true);
      List<ActivityInstance> w = getWorklist();
      Assert.assertEquals("worklist", 1, w.size());
      ActivityInstance ai = w.get(0);
      Assert.assertEquals("process instance", pi.getOID(), ai.getProcessInstanceOID());
      Assert.assertEquals("activity instance", "EnterOrderData", ai.getActivity().getId());
      Map<String, Object> order = CollectionUtils.newMap();
      order.put("date", new Date());
      order.put("customerId", customerId);
      ai =
          complete(
              ai, PredefinedConstants.DEFAULT_CONTEXT, Collections.singletonMap("Order", order));

      try {
        ProcessInstanceStateBarrier.instance().await(pi.getOID(), ProcessInstanceState.Completed);
      } catch (Exception e) {
      }
      w = getWorklist();
    }
  }
  @Test(timeout = 1000)
  public void testFasterSource() {
    NbpPublishSubject<Integer> source = NbpPublishSubject.create();
    NbpBlockingObservable<Integer> blocker = source.toBlocking();

    Iterable<Integer> iter = blocker.latest();
    Iterator<Integer> it = iter.iterator();

    source.onNext(1);

    Assert.assertEquals(Integer.valueOf(1), it.next());

    source.onNext(2);
    source.onNext(3);

    Assert.assertEquals(Integer.valueOf(3), it.next());

    source.onNext(4);
    source.onNext(5);
    source.onNext(6);

    Assert.assertEquals(Integer.valueOf(6), it.next());

    source.onNext(7);
    source.onComplete();

    Assert.assertEquals(false, it.hasNext());
  }
コード例 #7
0
  private void assertTableContent(
      final JdbcContentPersistenceService tested,
      final String sysContentType,
      final String id,
      final Date expectedUpdated) {
    final String tablename = tested.getTableName(sysContentType);

    try (final Connection conn = this.getTested().searchiskoDs.getConnection();
        final PreparedStatement statement =
            conn.prepareStatement(
                String.format(
                    "select sys_content_type, updated from %s where id = ?", tablename))) {
      statement.setString(1, id);
      try (final ResultSet rs = statement.executeQuery()) {
        Assert.assertTrue(rs.next());
        Assert.assertEquals(sysContentType, rs.getString(1));
        Timestamp actualTimestamp = rs.getTimestamp(2);
        if (expectedUpdated != null) {
          Assert.assertEquals(new Timestamp(expectedUpdated.getTime()), actualTimestamp);
        } else {
          Assert.assertNotNull(actualTimestamp);
        }
      }
    } catch (SQLException e) {
      Assert.fail(e.getMessage());
    }
  }
  @Test(timeout = 1000)
  public void testSameSourceMultipleIterators() {
    TestScheduler scheduler = new TestScheduler();

    NbpBlockingObservable<Long> source =
        NbpObservable.interval(1, TimeUnit.SECONDS, scheduler).take(10).toBlocking();

    Iterable<Long> iter = source.latest();

    for (int j = 0; j < 3; j++) {
      Iterator<Long> it = iter.iterator();

      // only 9 because take(10) will immediately call onCompleted when receiving the 10th item
      // which onCompleted will overwrite the previous value
      for (int i = 0; i < 9; i++) {
        scheduler.advanceTimeBy(1, TimeUnit.SECONDS);

        Assert.assertEquals(true, it.hasNext());

        Assert.assertEquals(Long.valueOf(i), it.next());
      }

      scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
      Assert.assertEquals(false, it.hasNext());
    }
  }
コード例 #9
0
  @Test
  public void testIterable2() {
    addFromArray(this.set, this.keyE, this.key1, this.key2, this.key2, this.key3, this.key4);
    this.set.remove(this.k2);
    Assert.assertEquals(4, this.set.size());

    int counted = 0;
    for (final KTypeCursor<KType> cursor : this.set) {
      if (cursor.index == getKeys(this.set).length) {

        Assert.assertTrue(this.isAllocatedDefaultKey(this.set));
        TestUtils.assertEquals2(this.keyE, cursor.value);
        counted++;
        continue;
      }

      Assert.assertTrue(this.set.contains(cursor.value));
      TestUtils.assertEquals2(cursor.value, this.getKeys(this.set)[cursor.index]);
      counted++;
    }
    Assert.assertEquals(counted, this.set.size());

    this.set.clear();
    Assert.assertFalse(this.set.iterator().hasNext());
  }
コード例 #10
0
ファイル: MonitorGraphTest.java プロジェクト: headius/graal
 @Test
 public void test2() {
   StructuredGraph graph = parseAndProcess("test2Snippet");
   NodeIterable<MonitorExitNode> monitors = graph.getNodes(MonitorExitNode.class);
   Assert.assertEquals(1, monitors.count());
   Assert.assertEquals(monitors.first().stateAfter().bci, 3);
 }
コード例 #11
0
ファイル: JavaDatasetSuite.java プロジェクト: pallavipr/spark
  @Test
  public void testCommonOperation() {
    List<String> data = Arrays.asList("hello", "world");
    Dataset<String> ds = context.createDataset(data, Encoders.STRING());
    Assert.assertEquals("hello", ds.first());

    Dataset<String> filtered =
        ds.filter(
            new FilterFunction<String>() {
              @Override
              public boolean call(String v) throws Exception {
                return v.startsWith("h");
              }
            });
    Assert.assertEquals(Arrays.asList("hello"), filtered.collectAsList());

    Dataset<Integer> mapped =
        ds.map(
            new MapFunction<String, Integer>() {
              @Override
              public Integer call(String v) throws Exception {
                return v.length();
              }
            },
            Encoders.INT());
    Assert.assertEquals(Arrays.asList(5, 5), mapped.collectAsList());

    Dataset<String> parMapped =
        ds.mapPartitions(
            new MapPartitionsFunction<String, String>() {
              @Override
              public Iterable<String> call(Iterator<String> it) throws Exception {
                List<String> ls = new LinkedList<String>();
                while (it.hasNext()) {
                  ls.add(it.next().toUpperCase());
                }
                return ls;
              }
            },
            Encoders.STRING());
    Assert.assertEquals(Arrays.asList("HELLO", "WORLD"), parMapped.collectAsList());

    Dataset<String> flatMapped =
        ds.flatMap(
            new FlatMapFunction<String, String>() {
              @Override
              public Iterable<String> call(String s) throws Exception {
                List<String> ls = new LinkedList<String>();
                for (char c : s.toCharArray()) {
                  ls.add(String.valueOf(c));
                }
                return ls;
              }
            },
            Encoders.STRING());
    Assert.assertEquals(
        Arrays.asList("h", "e", "l", "l", "o", "w", "o", "r", "l", "d"),
        flatMapped.collectAsList());
  }
コード例 #12
0
 @Test
 public void testNullKey() {
   this.set.add((KType) null);
   Assert.assertEquals(1, this.set.size());
   Assert.assertTrue(this.set.contains(null));
   Assert.assertTrue(this.set.remove(null));
   Assert.assertEquals(0, this.set.size());
   Assert.assertFalse(this.set.contains(null));
 }
コード例 #13
0
  /*! #if ($TemplateOptions.KTypeGeneric) !*/
  @SuppressWarnings("unchecked")
  @Test
  public void testHashCodeWithNulls() {
    final KTypeSet<KType> l1 = getFrom(this.k1, null, this.k3);
    final KTypeSet<KType> l2 = getFrom(this.k1, null);
    l2.add(this.k3);

    Assert.assertEquals(l1.hashCode(), l2.hashCode());
    Assert.assertEquals(l1, l2);
  }
コード例 #14
0
  @Test
  public void testAddAll() {
    final KTypeSet<KType> set2 = createNewSetInstance();
    addFromArray(set2, asArray(1, 2));
    addFromArray(this.set, asArray(0, 1));

    Assert.assertEquals(1, this.set.addAll(set2));
    Assert.assertEquals(0, this.set.addAll(set2));

    Assert.assertEquals(3, this.set.size());
    TestUtils.assertSortedListEquals(this.set.toArray(), 0, 1, 2);
  }
コード例 #15
0
  @Test
  public void testClear() {
    addFromArray(this.set, asArray(1, 2, 3));
    this.set.clear();
    checkConsistency();
    Assert.assertEquals(0, this.set.size());

    addFromArray(this.set, asArray(0, 2, 8));
    this.set.clear();
    checkConsistency();
    Assert.assertEquals(0, this.set.size());
  }
コード例 #16
0
  @Test
  public void testRemoveAllFromLookupContainer() {
    addFromArray(this.set, asArray(0, 1, 2, 3, 4));

    // test against concrete HashSet
    final KTypeHashSet<KType> set2 = new KTypeHashSet<KType>();
    set2.add(asArray(1, 3, 5));

    Assert.assertEquals(2, this.set.removeAll(set2));

    Assert.assertEquals(3, this.set.size());
    TestUtils.assertSortedListEquals(this.set.toArray(), 0, 2, 4);
  }
コード例 #17
0
  @Test
  public void testPooledIteratorFullIteratorLoop() {
    // A) for-each loop interrupted

    // must accommodate even the smallest primitive type
    // so that the iteration do not break before it should...
    final int TEST_SIZE = 126;
    final long TEST_ROUNDS = 5000;

    final KTypeSet<KType> testContainer = createSetWithOrderedData(TEST_SIZE);

    final long checksum =
        testContainer.forEach(
                new KTypeProcedure<KType>() {

                  long count;

                  @Override
                  public void apply(final KType value) {
                    this.count += castType(value);
                  }
                })
            .count;

    long testValue = 0;
    final int startingPoolSize = getEntryPoolSize(testContainer);

    for (int round = 0; round < TEST_ROUNDS; round++) {
      // Classical iterator loop, with manually allocated Iterator
      final int initialPoolSize = getEntryPoolSize(testContainer);

      final AbstractIterator<KTypeCursor<KType>> loopIterator =
          (AbstractIterator<KTypeCursor<KType>>) testContainer.iterator();

      Assert.assertEquals(initialPoolSize - 1, getEntryPoolSize(testContainer));

      testValue = 0;
      while (loopIterator.hasNext()) {
        testValue += castType(loopIterator.next().value);
      } // end IteratorLoop

      // iterator is returned automatically to its pool, by normal iteration termination
      Assert.assertEquals(initialPoolSize, getEntryPoolSize(testContainer));

      // checksum
      Assert.assertEquals(checksum, testValue);
    } // end for rounds

    // pool initial size is untouched anyway
    Assert.assertEquals(startingPoolSize, getEntryPoolSize(testContainer));
  }
コード例 #18
0
  @Repeat(iterations = 10)
  @Test
  public void testPreallocatedSize() {
    final Random randomVK = RandomizedTest.getRandom();
    // Test that the container do not resize if less that the initial size

    // 1) Choose a random number of elements
    /*! #if ($TemplateOptions.isKType("GENERIC", "INT", "LONG", "FLOAT", "DOUBLE")) !*/
    final int PREALLOCATED_SIZE = randomVK.nextInt(10000);
    /*!
    #elseif ($TemplateOptions.isKType("SHORT", "CHAR"))
     int PREALLOCATED_SIZE = randomVK.nextInt(1500);
    #else
      int PREALLOCATED_SIZE = randomVK.nextInt(126);
    #end !*/

    final KTypeSet<KType> newSet =
        createNewSetInstance(PREALLOCATED_SIZE, HashContainers.DEFAULT_LOAD_FACTOR);

    // computed real capacity
    final int realCapacity = newSet.capacity();

    // 3) Add PREALLOCATED_SIZE different values. At the end, size() must be == realCapacity,
    // and internal buffer/allocated must not have changed of size
    final int contructorBufferSize = getKeys(newSet).length;

    Assert.assertEquals(contructorBufferSize, getKeys(newSet).length);

    for (int i = 0; i < 1.5 * realCapacity; i++) {

      newSet.add(cast(i));

      // internal size has not changed until realCapacity
      if (newSet.size() <= realCapacity) {

        Assert.assertEquals(contructorBufferSize, getKeys(newSet).length);
      }

      if (contructorBufferSize < getKeys(newSet).length) {
        // The container as just reallocated, its actual size must be not too far from the previous
        // capacity:
        Assert.assertTrue(
            "Container as reallocated at size = "
                + newSet.size()
                + " with previous capacity = "
                + realCapacity,
            (newSet.size() - realCapacity) <= 3);
        break;
      }
    }
  }
コード例 #19
0
  /**
   * 运行时,添加JVM参数“-Dsun.net.http.retryPost=false”,可阻止自动重连。
   *
   * @see 'http://www.coderanch.com/t/490463/sockets/java/Timeout-retry-URLHTTPRequest'
   */
  @Test
  public void testConnectionResetByHttpURLConnection() throws IOException {
    testConnectionResetCount = 0;

    String resp = null;
    try {
      HttpURLConnection conn =
          (HttpURLConnection) new URL("http://localhost:65532/soso").openConnection();
      conn.setDoOutput(true);
      conn.setRequestMethod("POST");
      conn.getOutputStream().write("username".getBytes());
      resp = conn.getResponseCode() + "";
    } catch (IOException e) {
      Throwable ee = ExceptionUtils.getRootCause(e);
      if (ee == null) {
        ee = e;
      }
      Logger.error(this, "", ee);
      Assert.assertNotSame(NoHttpResponseException.class, ee.getClass());
      Assert.assertSame(SocketException.class, ee.getClass());
      Assert.assertTrue(
          "Connection reset".equals(ee.getMessage())
              || "Socket closed".equals(ee.getMessage())
              || "Unexpected end of file from server".equals(ee.getMessage()));
    } finally {
      Logger.info(
          this,
          "resp[HttpURLConnection]-["
              + testConnectionResetCount
              + "]=========["
              + resp
              + "]=========");
    }
    Assert.assertEquals(2, testConnectionResetCount);
  }
コード例 #20
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()));
  }
コード例 #21
0
  /**
   * Run some random insertions/ deletions and compare the results against <code>java.util.HashSet
   * </code>.
   */
  @Test
  public void testAgainstHashMap() {
    final java.util.Random rnd = new Random(0xBADCAFE);
    final java.util.HashSet<KType> other = new java.util.HashSet<KType>();

    for (int size = 1000; size < 20000; size += 4000) {
      other.clear();
      this.set.clear();

      for (int round = 0; round < size * 20; round++) {
        final KType key = cast(rnd.nextInt(size));

        if (rnd.nextBoolean()) {
          other.add(key);
          this.set.add(key);

          Assert.assertTrue(this.set.contains(key));
        } else {
          Assert.assertTrue(
              "size= " + size + ", round = " + round, other.remove(key) == this.set.remove(key));
        }

        Assert.assertEquals(other.size(), this.set.size());
      }
    }
  }
コード例 #22
0
ファイル: SignUpTests.java プロジェクト: samkiev/GL
 @Test
 public void passwordDidntMatchError() {
   SignUpResultPage resultPage =
       signUpPage.signUp(correctName, password, incorrectConfirmPassword, "", correctEmail);
   Assert.assertEquals(
       Source.getValue("SignUpErrorPasswordDidntMatchError"), resultPage.getErrorText());
 }
コード例 #23
0
  @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"));
  }
コード例 #24
0
  @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();
  }
コード例 #25
0
ファイル: JavaDatasetSuite.java プロジェクト: pallavipr/spark
 @Test
 public void testTake() {
   List<String> data = Arrays.asList("hello", "world");
   Dataset<String> ds = context.createDataset(data, Encoders.STRING());
   List<String> collected = ds.takeAsList(1);
   Assert.assertEquals(Arrays.asList("hello"), collected);
 }
コード例 #26
0
  @Test
  public void testAdd() {
    Assert.assertTrue(this.set.add(this.key1));
    Assert.assertFalse(this.set.add(this.key1));
    Assert.assertEquals(1, this.set.size());

    Assert.assertTrue(this.set.add(this.keyE));
    Assert.assertFalse(this.set.add(this.keyE));

    Assert.assertEquals(2, this.set.size());

    Assert.assertTrue(this.set.add(this.key2));
    Assert.assertFalse(this.set.add(this.key2));

    Assert.assertEquals(3, this.set.size());
  }
コード例 #27
0
  /**
   * Check that the set is consistent, i.e all allocated slots are reachable by get(), and all
   * not-allocated contains nulls if Generic
   *
   * @param set
   */
  @After
  public void checkConsistency() {
    if (this.set != null) {
      int occupied = 0;

      final int mask = getKeys(this.set).length - 1;

      for (int i = 0; i < getKeys(this.set).length; i++) {
        if (!is_allocated(i, Intrinsics.<KType[]>cast(getKeys(this.set)))) {
          // if not allocated, generic version if patched to null for GC sake
          /*! #if ($TemplateOptions.KTypeGeneric) !*/
          TestUtils.assertEquals2(this.keyE, getKeys(this.set)[i]);
          /*! #end !*/
        } else {
          // try to reach the key by contains()
          Assert.assertTrue(this.set.contains(Intrinsics.<KType>cast(getKeys(this.set)[i])));

          occupied++;
        }
      }

      if (isAllocatedDefaultKey(this.set)) {

        // try to reach the key by contains()
        Assert.assertTrue(this.set.contains(this.keyE));

        occupied++;
      }

      Assert.assertEquals(occupied, this.set.size());
    }
  }
コード例 #28
0
 private static void validatePeak2(ISpectrumPeak pSp, double pPeak, double pPeak1) {
   Set<Integer> goodMasses = buildMassSet();
   final double chargeRatio = pSp.getMassChargeRatio();
   validateAsInts(chargeRatio, pPeak);
   double peak = pSp.getPeak();
   Assert.assertEquals(pPeak1, peak, ALLOWED_INTENSITY_ERROR);
 }
コード例 #29
0
  @Test
  public void testSoakTestWithRandomData() throws IOException, InterruptedException {

    // for (int i = 30; i < 50; i++) {
    System.out.print("SoakTesting ");
    int max = 1000000;
    for (int j = 1; j < max; j++) {
      if (j % 100 == 0) System.out.print(".");
      Random rnd = new Random(System.currentTimeMillis());

      final ChronicleMap<Integer, CharSequence> map = rnd.nextBoolean() ? map1 : map2;

      if (rnd.nextBoolean()) {
        map.put((int) rnd.nextInt(100), "test" + j);
      } else {
        map.remove((int) rnd.nextInt(100));
      }
    }

    System.out.println("\nwaiting till equal");

    waitTillUnchanged(1000);
    System.out.println("time t=" + t);
    Assert.assertEquals(new TreeMap(map1), new TreeMap(map2));
  }
コード例 #30
0
  @Test
  public void testConnectionResetByHttpClientUtils() throws IOException {
    testConnectionResetCount = 0;

    httpClientUtils = new HttpClientUtils();
    httpClientUtils.initHttpClient();
    Logger.info(this, "-------------- HttpClient initialized -------------");

    String resp = null;
    try {
      resp = httpClientUtils.get("http://localhost:65532/soso");
    } catch (IOException e) {
      Throwable ee = ExceptionUtils.getRootCause(e);
      if (ee == null) {
        ee = e;
      }
      Logger.error(this, "", ee);
      Assert.assertNotSame(NoHttpResponseException.class, ee.getClass());
      Assert.assertSame(SocketException.class, ee.getClass());
      Assert.assertTrue(
          "Connection reset".equals(ee.getMessage())
              || "Socket closed".equals(ee.getMessage())
              || "Unexpected end of file from server".equals(ee.getMessage()));
    } finally {
      Logger.info(
          this,
          "resp[HttpURLConnection]-["
              + testConnectionResetCount
              + "]=========["
              + resp
              + "]=========");
    }
    Assert.assertEquals(1, testConnectionResetCount);
  }