com.carrotsearch.randomizedtesting.annotations.Repeat Java Examples

The following examples show how to use com.carrotsearch.randomizedtesting.annotations.Repeat. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RandomPlaneTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
@Repeat(iterations = 10)
public void testPolygonAccuracy() {
  PlanetModel planetModel = randomPlanetModel();
  GeoPoint point1 = randomGeoPoint(planetModel);
  for (int i= 0; i < 1000; i++) {
    double dist = random().nextDouble() * 1e-6 + Vector.MINIMUM_ANGULAR_RESOLUTION;
    GeoPoint point2 = planetModel.surfacePointOnBearing(point1, dist, 0);
    GeoPoint point3 = planetModel.surfacePointOnBearing(point1, dist, 0.5 * Math.PI);

    List<GeoPoint> points = new ArrayList<>();
    points.add(point1);
    points.add(point2);
    points.add(point3);
    GeoPolygonFactory.makeGeoPolygon(planetModel, points);

  }
}
 
Example #2
Source File: DatumStatusCounterTest.java    From streams with Apache License 2.0 6 votes vote down vote up
/**
 * Test that you can increment passes and it returns the correct count
 * @throws Exception
 */
@Test
@Repeat(iterations = 3)
public void testPassed() throws Exception {
  DatumStatusCounter counter = new DatumStatusCounter(MBEAN_ID, STREAM_ID, STREAM_START_TIME);
  int numIncrements = randomIntBetween(1, 100000);
  for(int i=0; i < numIncrements; ++i) {
    counter.incrementPassedCount();
  }
  Assert.assertEquals(numIncrements, counter.getNumPassed());

  unregisterMXBean();

  counter = new DatumStatusCounter(MBEAN_ID, STREAM_ID, STREAM_START_TIME);
  numIncrements = randomIntBetween(1, 100000);
  long total = 0;
  for(int i=0; i < numIncrements; ++i) {
    long delta = randomIntBetween(1, 100);
    total += delta;
    counter.incrementPassedCount(delta);
  }
  Assert.assertEquals(total, counter.getNumPassed());
}
 
Example #3
Source File: DatumStatusCounterTest.java    From streams with Apache License 2.0 6 votes vote down vote up
/**
 * Test that you can increment failed and it returns the correct count
 * @throws Exception
 */
@Test
@Repeat(iterations = 3)
public void testFailed() throws Exception {
  DatumStatusCounter counter = new DatumStatusCounter(MBEAN_ID, STREAM_ID, STREAM_START_TIME);
  int numIncrements = randomIntBetween(1, 100000);
  for(int i=0; i < numIncrements; ++i) {
    counter.incrementFailedCount();
  }
  Assert.assertEquals(numIncrements, counter.getNumFailed());

  unregisterMXBean();

  counter = new DatumStatusCounter(MBEAN_ID, STREAM_ID, STREAM_START_TIME);
  numIncrements = randomIntBetween(1, 100000);
  long total = 0;
  for(int i=0; i < numIncrements; ++i) {
    long delta = randomIntBetween(1, 100);
    total += delta;
    counter.incrementFailedCount(delta);
  }
  Assert.assertEquals(total, counter.getNumFailed());
}
 
Example #4
Source File: StreamsTaskCounterTest.java    From streams with Apache License 2.0 6 votes vote down vote up
/**
 * Test errors increments correctly and returns expected value
 * @throws Exception
 */
@Test
@Repeat(iterations = 3)
public void testError() throws Exception {
  StreamsTaskCounter counter = new StreamsTaskCounter(MBEAN_ID, STREAM_ID, STREAM_START_TIME);
  int numIncrements = randomIntBetween(1, 100000);
  for(int i=0; i < numIncrements; ++i) {
    counter.incrementErrorCount();
  }
  Assert.assertEquals(numIncrements, counter.getNumUnhandledErrors());

  unregisterMXBean();

  counter = new StreamsTaskCounter(MBEAN_ID, STREAM_ID, STREAM_START_TIME);
  numIncrements = randomIntBetween(1, 100000);
  long total = 0;
  for(int i=0; i < numIncrements; ++i) {
    long delta = randomIntBetween(1, 100);
    total += delta;
    counter.incrementErrorCount(delta);
  }
  Assert.assertEquals(total, counter.getNumUnhandledErrors());
}
 
Example #5
Source File: TestMaxFailuresRule.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Repeat(iterations = TOTAL_ITERS)
public void testLeaveZombie() {
  if (++testNum == 2) {
    zombie = new Thread() {
      @Override
      public void run() {
        while (true) {
          try {
            die.await();
            return;
          } catch (Exception e) { /* ignore */ }
        }
      }
    };
    zombie.start();
  }
}
 
Example #6
Source File: StreamsTaskCounterTest.java    From streams with Apache License 2.0 6 votes vote down vote up
/**
 * Test received increments correctly and returns expected value
 * @throws Exception
 */
@Test
@Repeat(iterations = 3)
public void testReceived() throws Exception {
  StreamsTaskCounter counter = new StreamsTaskCounter(MBEAN_ID, STREAM_ID, STREAM_START_TIME);
  int numIncrements = randomIntBetween(1, 100000);
  for(int i=0; i < numIncrements; ++i) {
    counter.incrementReceivedCount();
  }
  Assert.assertEquals(numIncrements, counter.getNumReceived());

  unregisterMXBean();

  counter = new StreamsTaskCounter(MBEAN_ID, STREAM_ID, STREAM_START_TIME);
  numIncrements = randomIntBetween(1, 100000);
  long total = 0;
  for(int i=0; i < numIncrements; ++i) {
    long delta = randomIntBetween(1, 100);
    total += delta;
    counter.incrementReceivedCount(delta);
  }
  Assert.assertEquals(total, counter.getNumReceived());
}
 
Example #7
Source File: StreamsTaskCounterTest.java    From streams with Apache License 2.0 6 votes vote down vote up
/**
 * Test emitted increments correctly and returns expected value
 * @throws Exception
 */
@Test
@Repeat(iterations = 3)
public void testEmitted() throws Exception {
  StreamsTaskCounter counter = new StreamsTaskCounter(MBEAN_ID, STREAM_ID, STREAM_START_TIME);
  int numIncrements = randomIntBetween(1, 100000);
  for(int i=0; i < numIncrements; ++i) {
    counter.incrementEmittedCount();
  }
  Assert.assertEquals(numIncrements, counter.getNumEmitted());

  unregisterMXBean();

  counter = new StreamsTaskCounter(MBEAN_ID, STREAM_ID, STREAM_START_TIME);
  numIncrements = randomIntBetween(1, 100000);
  long total = 0;
  for(int i=0; i < numIncrements; ++i) {
    long delta = randomIntBetween(1, 100);
    total += delta;
    counter.incrementEmittedCount(delta);
  }
  Assert.assertEquals(total, counter.getNumEmitted());
}
 
Example #8
Source File: S2PrefixTreeTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
@Repeat(iterations = 10)
public void testPrecision() {
  int arity = random().nextInt(3) +1;
  SpatialContext context = new Geo3dSpatialContextFactory().newSpatialContext();
  S2PrefixTree tree = new S2PrefixTree(context, S2PrefixTree.getMaxLevels(arity), arity);
  double precision = random().nextDouble();
  int level = tree.getLevelForDistance(precision);
  Point point = context.getShapeFactory().pointXY(0, 0);
  CellIterator iterator = tree.getTreeCellIterator(point, level);
  S2PrefixTreeCell cell = null;
  while (iterator.hasNext()) {
    cell = (S2PrefixTreeCell)iterator.next();
  }
  assertTrue(cell.getLevel() == level);
  double precisionCell = S2Projections.MAX_WIDTH.getValue(cell.cellId.level());
  assertTrue(precision > precisionCell);
}
 
Example #9
Source File: S2PrefixTreeTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
@Repeat(iterations = 10)
public void testDistanceAndLevels() {
  S2PrefixTree tree = new S2PrefixTree(new Geo3dSpatialContextFactory().newSpatialContext(), S2PrefixTree.getMaxLevels(1), 1);

  double randomDist = random().nextDouble() * 5;
  int levelDistance = tree.getLevelForDistance(randomDist);
  double distanceLevel = tree.getDistanceForLevel(levelDistance);
  assertTrue(randomDist > distanceLevel);


  tree = new S2PrefixTree(new Geo3dSpatialContextFactory().newSpatialContext(), S2PrefixTree.getMaxLevels(2), 2);

  levelDistance = tree.getLevelForDistance(randomDist);
  distanceLevel = tree.getDistanceForLevel(levelDistance);
  assertTrue(randomDist > distanceLevel);

  tree = new S2PrefixTree(new Geo3dSpatialContextFactory().newSpatialContext(), S2PrefixTree.getMaxLevels(3), 3);

  levelDistance = tree.getLevelForDistance(randomDist);
  distanceLevel = tree.getDistanceForLevel(levelDistance);
  assertTrue(randomDist > distanceLevel);

}
 
Example #10
Source File: RandomPlaneTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
@Repeat(iterations = 10)
public void testPlaneThreePointsAccuracy() {
  PlanetModel planetModel = randomPlanetModel();
  for (int i= 0; i < 1000; i++) {
    GeoPoint point1 = randomGeoPoint(planetModel);
    double dist = random().nextDouble() * Math.PI - Vector.MINIMUM_ANGULAR_RESOLUTION;
    double bearing = random().nextDouble() * 2 * Math.PI;
    GeoPoint point2 = planetModel.surfacePointOnBearing(point1, dist, bearing );
    dist = random().nextDouble() * Vector.MINIMUM_ANGULAR_RESOLUTION + Vector.MINIMUM_ANGULAR_RESOLUTION;
    bearing = random().nextDouble() * 2 * Math.PI;
    GeoPoint point3 = planetModel.surfacePointOnBearing(point1, dist, bearing );
    GeoPoint check = randomGeoPoint(planetModel);
    SidedPlane plane  = SidedPlane.constructNormalizedThreePointSidedPlane(check, point1, point2, point3);
    String msg = planetModel + " point 1: " + point1 + ", point 2: " + point2 + ", point 3: " + point3 + " , check: " + check;
    if (plane == null) {
      fail(msg);
    }
    // This is not expected
    //assertTrue(plane.evaluate(check) + " " + msg, plane.isWithin(check));
    assertTrue(plane.evaluate(point1) + " " +msg, plane.isWithin(point1));
    assertTrue(plane.evaluate(point2) + " " +msg, plane.isWithin(point2));
    assertTrue(plane.evaluate(point3) + " " +msg, plane.isWithin(point3));
  }
}
 
Example #11
Source File: RandomPlaneTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
@Repeat(iterations = 10)
public void testPlaneAccuracy() {
  PlanetModel planetModel = randomPlanetModel();
  GeoPoint point1 = randomGeoPoint(planetModel);
  for (int i= 0; i < 1000; i++) {
    double dist = random().nextDouble() * Vector.MINIMUM_ANGULAR_RESOLUTION + Vector.MINIMUM_ANGULAR_RESOLUTION;
    double bearing = random().nextDouble() * 2 * Math.PI;
    GeoPoint point2 = planetModel.surfacePointOnBearing(point1, dist, bearing );
    GeoPoint check = randomGeoPoint(planetModel);
    if (!point1.isNumericallyIdentical(point2)) {
      SidedPlane plane = new SidedPlane(check, point1, point2);
      String msg = dist + " point 1: " + point1 + ", point 2: " + point2 + " , check: " + check;
      assertTrue(msg, plane.isWithin(check));
      assertTrue(msg, plane.isWithin(point2));
      assertTrue(msg, plane.isWithin(point1));
    }
    else {
      assertFalse("numerically identical", true);
    }
  }
}
 
Example #12
Source File: GeoExactCircleTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * in LUCENE-8054 we have problems with exact circles that have
 * edges that are close together. This test creates those circles with the same
 * center and slightly different radius.
 */
@Test
@Repeat(iterations = 100)
public void testRandomLUCENE8054() {
  PlanetModel planetModel = randomPlanetModel();
  GeoCircle circle1 = (GeoCircle) randomGeoAreaShape(EXACT_CIRCLE, planetModel);
  // new radius, a bit smaller than the generated one!
  double radius = circle1.getRadius() *  (1 - 0.01 * random().nextDouble());
  //circle with same center and new radius
  GeoCircle circle2 = GeoCircleFactory.makeExactGeoCircle(planetModel,
      circle1.getCenter().getLatitude(),
      circle1.getCenter().getLongitude(),
      radius, 1e-5 );
  StringBuilder b = new StringBuilder();
  b.append("circle1: " + circle1 + "\n");
  b.append("circle2: " + circle2);
  //It cannot be disjoint, same center!
  assertTrue(b.toString(), circle1.getRelationship(circle2) != GeoArea.DISJOINT);
}
 
Example #13
Source File: GeoExactCircleTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
@Repeat(iterations = 100)
public void RandomPointBearingCardinalTest(){
  //surface distance calculations methods start not converging when
  //planet scaledFlattening > 0.4
  PlanetModel planetModel;
  do {
    double ab = random().nextDouble() * 2;
    double c = random().nextDouble() * 2;
    if (random().nextBoolean()) {
      planetModel = new PlanetModel(ab, c);
    } else {
      planetModel = new PlanetModel(c, ab);
    }
  } while (Math.abs(planetModel.scaledFlattening) > 0.4);
  GeoPoint center = randomGeoPoint(planetModel);
  double radius =  random().nextDouble() * 0.9 * planetModel.minimumPoleDistance;
  checkBearingPoint(planetModel, center, radius, 0);
  checkBearingPoint(planetModel, center, radius, 0.5 * Math.PI);
  checkBearingPoint(planetModel, center, radius, Math.PI);
  checkBearingPoint(planetModel, center, radius, 1.5 * Math.PI);
}
 
Example #14
Source File: WindowFunctionBatchIteratorTest.java    From crate with Apache License 2.0 6 votes vote down vote up
@Test
@Repeat (iterations = 100)
public void testOptimizedFindFirstNonPeerMatchesBehaviorOfTrivial() {
    int length = randomIntBetween(10, 1000);
    ArrayList<Integer> numbers = new ArrayList<>(length);
    for (int i = 0; i < length; i++) {
        numbers.add(randomInt());
    }
    Comparator<Integer> comparingInt = Comparator.comparingInt(x -> x);
    numbers.sort(comparingInt);
    int begin = randomIntBetween(0, length - 1);
    int end = randomIntBetween(begin, length - 1);

    int expectedPosition = findFirstNonPeerTrivial(numbers, begin, end, comparingInt);
    assertThat(
        "Expected firstNonPeer position=" + expectedPosition + " for " + numbers + "[" + begin + ":" + end + "]",
        expectedPosition,
        Matchers.is(Lists2.findFirstNonPeer(numbers, begin, end, comparingInt)
        )
    );
}
 
Example #15
Source File: SortTest.java    From crate with Apache License 2.0 6 votes vote down vote up
@Test
@Repeat(iterations = 50)
public void testParallelSortYieldsTheSameResultAsListSort() throws Exception {
    int length = randomIntBetween(2, 1000);
    ArrayList<Integer> numbers = new ArrayList<>();
    for (int i = 0; i < length; i++) {
        numbers.add(randomInt());
    }
    var unsortedNumbers = new ArrayList<>(numbers);
    numbers.sort(Comparator.comparingInt(x -> x));
    assertThat(
        numbers,
        is(Sort.parallelSort(
            unsortedNumbers,
            Comparator.comparingInt(x -> x),
            randomIntBetween(1, 1000),
            randomIntBetween(1, 4),
            executor
            ).get(5, TimeUnit.SECONDS))
    );
}
 
Example #16
Source File: InsertIntoIntegrationTest.java    From crate with Apache License 2.0 6 votes vote down vote up
/**
 * Test that when an error happens on the primary, the record should never be inserted on the replica.
 * Since we cannot force a select statement to be executed on a replica, we repeat this test to increase the chance.
 */
@Repeat(iterations = 5)
@Test
public void testInsertWithErrorMustNotBeInsertedOnReplica() throws Exception {
    execute("create table test (id integer primary key, name string) with (number_of_replicas=1)");
    ensureYellow();
    execute("insert into test (id, name) values (1, 'foo')");
    assertThat(response.rowCount(), is(1L));
    try {
        execute("insert into test (id, name) values (1, 'bar')");
        fail("Expecting a DuplicateKeyException");
    } catch (SQLActionException e) {
        assertThat(e.getMessage(), containsString("DuplicateKeyException"));
    }
    refresh();

    // we want to read from the replica but cannot force it, lets select twice to increase chances
    execute("select _version, name from test");
    assertThat((String) response.rows()[0][1], is("foo"));
    assertThat((Long) response.rows()[0][0], is(1L));
    execute("select _version, name from test");
    assertThat((String) response.rows()[0][1], is("foo"));
    assertThat((Long) response.rows()[0][0], is(1L));
}
 
Example #17
Source File: TestSolr4Spatial2.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test @Repeat(iterations = 10)
public void testLLPDecodeIsStableAndPrecise() throws Exception {
  // test that LatLonPointSpatialField decode of docValue will round-trip (re-index then re-decode) to the same value
  @SuppressWarnings({"resource", "IOResourceOpenedButNotSafelyClosed"})
  SolrClient client = new EmbeddedSolrServer(h.getCore());// do NOT close it; it will close Solr

  final String fld = "llp_1_dv_dvasst";
  String ptOrig = GeoTestUtil.nextLatitude() + "," + GeoTestUtil.nextLongitude();
  assertU(adoc("id", "0", fld, ptOrig));
  assertU(commit());
  // retrieve it (probably less precision)
  String ptDecoded1 = (String) client.query(params("q", "id:0")).getResults().get(0).get(fld);
  // now write it back
  assertU(adoc("id", "0", fld, ptDecoded1));
  assertU(commit());
  // retrieve it; assert that it's the same as written
  String ptDecoded2 = (String) client.query(params("q", "id:0")).getResults().get(0).get(fld);
  assertEquals("orig:" + ptOrig, ptDecoded1, ptDecoded2);

  // test that the representation is pretty accurate
  final Point ptOrigObj = SpatialUtils.parsePoint(ptOrig, SpatialContext.GEO);
  final Point ptDecodedObj = SpatialUtils.parsePoint(ptDecoded1, SpatialContext.GEO);
  double deltaCentimeters = SpatialContext.GEO.calcDistance(ptOrigObj, ptDecodedObj) * DistanceUtils.DEG_TO_KM * 1000.0 * 100.0;
  //See javadocs of LatLonDocValuesField for these constants
  final Point absErrorPt = SpatialContext.GEO.getShapeFactory().pointXY(8.381903171539307E-8, 4.190951585769653E-8);
  double deltaCentimetersMax
      = SpatialContext.GEO.calcDistance(absErrorPt, 0,0) * DistanceUtils.DEG_TO_KM * 1000.0 * 100.0;
  assertEquals(1.0420371840922256, deltaCentimetersMax, 0.0);// just so that we see it in black & white in the test

  //max found by trial & error.  If we used 8 decimal places then we could get down to 1.04cm accuracy but then we
  // lose the ability to round-trip -- 40 would become 39.99999997  (ugh).
  assertTrue("deltaCm too high: " + deltaCentimeters, deltaCentimeters < 1.41);
  // Pt(x=105.29894270124083,y=-0.4371673760042398) to  Pt(x=105.2989428,y=-0.4371673) is 1.38568
}
 
Example #18
Source File: SpatialHeatmapFacetsTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
@Repeat(iterations = 3)
public void testPng() {
  //We test via round-trip randomized data:

  // Make random data
  int columns = random().nextInt(100) + 1;
  int rows = random().nextInt(100) + 1;
  int[] counts = new int[columns * rows];
  for (int i = 0; i < counts.length; i++) {
    final int ri = random().nextInt(10);
    if (ri >= 0 && ri <= 3) {
      counts[i] = ri; // 0 thru 3 will be made common
    } else if (ri > 3) {
      counts[i] = Math.abs(random().nextInt());//lots of other possible values up to max
    }
  }
  // Round-trip
  final byte[] bytes = FacetHeatmap.asPngBytes(columns, rows, counts, null);
  int[] countsOut = random().nextBoolean() ? new int[columns * rows] : null;
  int base = 0;
  if (countsOut != null) {
    base = 9;
    Arrays.fill(countsOut, base);
  }
  countsOut = FacetHeatmap.addPngToIntArray(bytes, countsOut);
  // Test equal
  assertEquals(counts.length, countsOut.length);
  for (int i = 0; i < countsOut.length; i++) {
    assertEquals(counts[i], countsOut[i] - base);//back out the base input to prove we added
  }
}
 
Example #19
Source File: RandomBinaryCodecTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
@Repeat(iterations = 10)
public void testRandomPointCodec() throws IOException{
  PlanetModel planetModel = randomPlanetModel();
  GeoPoint shape = randomGeoPoint(planetModel);
  ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  SerializableObject.writeObject(outputStream, shape);
  ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
  SerializableObject shapeCopy = SerializableObject.readObject(planetModel, inputStream);
  assertEquals(shape.toString(), shape, shapeCopy);
}
 
Example #20
Source File: StreamsTaskCounterTest.java    From streams with Apache License 2.0 5 votes vote down vote up
/**
 * Test error rate returns expected value
 * @throws Exception
 */
@Test
@Repeat(iterations = 3)
public void testErrorRate() throws Exception {
  StreamsTaskCounter counter = new StreamsTaskCounter(MBEAN_ID, STREAM_ID, STREAM_START_TIME);
  Assert.assertEquals(0.0, counter.getErrorRate(), 0);
  int failures = randomIntBetween(0, 100000);
  int received = randomIntBetween(0, 100000);
  counter.incrementReceivedCount(received);
  counter.incrementErrorCount(failures);
  Assert.assertEquals((double)failures / (double)(received), counter.getErrorRate(), 0);
}
 
Example #21
Source File: DatumStatusCounterTest.java    From streams with Apache License 2.0 5 votes vote down vote up
/**
 * Test failure rate returns expected values
 */
@Test
@Repeat(iterations = 3)
public void testFailureRate() {
  DatumStatusCounter counter = new DatumStatusCounter(MBEAN_ID, STREAM_ID, STREAM_START_TIME);
  Assert.assertEquals(0.0, counter.getFailRate(), 0);
  int failures = randomIntBetween(0, 100000);
  int passes = randomIntBetween(0, 100000);
  counter.incrementPassedCount(passes);
  counter.incrementFailedCount(failures);
  Assert.assertEquals((double)failures / (double)(passes + failures), counter.getFailRate(), 0);
}
 
Example #22
Source File: ThroughputQueueSingleThreadTest.java    From streams with Apache License 2.0 5 votes vote down vote up
/**
 * Test that take and put queue and dequeue data as expected and all
 * measurements form the queue are returning data.
 * @throws Exception
 */
@Test
@Repeat(iterations = 3)
public void testTakeAndPut() throws Exception {
  ThroughputQueue<Integer> queue = new ThroughputQueue<>();
  int putCount = randomIntBetween(1, 1000);
  for(int i=0; i < putCount; ++i) {
    queue.put(i);
    Assert.assertEquals(i+1, queue.size());
    Assert.assertEquals(queue.size(), queue.getCurrentSize());
  }
  safeSleep(100); //ensure measurable wait time
  int takeCount = randomIntBetween(1, putCount);
  for(int i=0; i < takeCount; ++i) {
    Integer element = queue.take();
    Assert.assertNotNull(element);
    Assert.assertEquals(i, element.intValue());
    Assert.assertEquals(putCount - (1+i), queue.size());
    Assert.assertEquals(queue.size(), queue.getCurrentSize());
  }
  Assert.assertEquals(putCount-takeCount, queue.size());
  Assert.assertEquals(queue.size(), queue.getCurrentSize());
  Assert.assertTrue(0.0 < queue.getMaxWait());
  Assert.assertTrue(0.0 < queue.getAvgWait());
  Assert.assertTrue(0.0 < queue.getThroughput());
  Assert.assertEquals(putCount, queue.getAdded());
  Assert.assertEquals(takeCount, queue.getRemoved());
}
 
Example #23
Source File: ThroughputQueueSingleThreadTest.java    From streams with Apache License 2.0 5 votes vote down vote up
/**
 * Test that add and remove queue and dequeue data as expected
 * and all measurements from the queue are returning data
 */
@Test
@Repeat(iterations = 3)
public void testAddAndRemove() {
  ThroughputQueue<Integer> queue = new ThroughputQueue<>();
  int putCount = randomIntBetween(1, 1000);
  for(int i=0; i < putCount; ++i) {
    queue.add(i);
    Assert.assertEquals(i+1, queue.size());
    Assert.assertEquals(queue.size(), queue.getCurrentSize());
  }
  safeSleep(100); //ensure measurable wait time
  int takeCount = randomIntBetween(1, putCount);
  for(int i=0; i < takeCount; ++i) {
    Integer element = queue.remove();
    Assert.assertNotNull(element);
    Assert.assertEquals(i, element.intValue());
    Assert.assertEquals(putCount - (1+i), queue.size());
    Assert.assertEquals(queue.size(), queue.getCurrentSize());
  }
  Assert.assertEquals(putCount-takeCount, queue.size());
  Assert.assertEquals(queue.size(), queue.getCurrentSize());
  Assert.assertTrue(0.0 < queue.getMaxWait());
  Assert.assertTrue(0.0 < queue.getAvgWait());
  Assert.assertTrue(0.0 < queue.getThroughput());
  Assert.assertEquals(putCount, queue.getAdded());
  Assert.assertEquals(takeCount, queue.getRemoved());
}
 
Example #24
Source File: ThroughputQueueSingleThreadTest.java    From streams with Apache License 2.0 5 votes vote down vote up
/**
 * Test that offer and poll queue and dequeue data as expected
 * and all measurements from the queue are returning data
 */
@Test
@Repeat(iterations = 3)
public void testOfferAndPoll() {
  ThroughputQueue<Integer> queue = new ThroughputQueue<>();
  int putCount = randomIntBetween(1, 1000);
  for(int i=0; i < putCount; ++i) {
    queue.offer(i);
    Assert.assertEquals(i+1, queue.size());
    Assert.assertEquals(queue.size(), queue.getCurrentSize());
  }
  safeSleep(100); //ensure measurable wait time
  int takeCount = randomIntBetween(1, putCount);
  for(int i=0; i < takeCount; ++i) {
    Integer element = queue.poll();
    Assert.assertNotNull(element);
    Assert.assertEquals(i, element.intValue());
    Assert.assertEquals(putCount - (1+i), queue.size());
    Assert.assertEquals(queue.size(), queue.getCurrentSize());
  }
  Assert.assertEquals(putCount-takeCount, queue.size());
  Assert.assertEquals(queue.size(), queue.getCurrentSize());
  Assert.assertTrue(0.0 < queue.getMaxWait());
  Assert.assertTrue(0.0 < queue.getAvgWait());
  Assert.assertTrue(0.0 < queue.getThroughput());
  Assert.assertEquals(putCount, queue.getAdded());
  Assert.assertEquals(takeCount, queue.getRemoved());
}
 
Example #25
Source File: ThroughputQueueMultiThreadTest.java    From streams with Apache License 2.0 5 votes vote down vote up
/**
 * Test multiple threads putting and taking from the queue while
 * this thread repeatedly calls the MXBean measurement methods.
 * Should hammer the queue with request from multiple threads
 * of all request types.  Purpose is to expose current modification exceptions
 * and/or dead locks.
 */
@Test
@Repeat(iterations = 3)
public void testMultiThreadAccessAndInteruptResponse() throws Exception {
  int putTakeThreadCount = randomIntBetween(1, 10);
  int dataCount = randomIntBetween(1, 2000000);
  int pollCount = randomIntBetween(1, 2000000);
  int maxSize = randomIntBetween(1, 1000);
  CountDownLatch finished = new CountDownLatch(putTakeThreadCount);
  ThroughputQueue queue = new ThroughputQueue(maxSize, MBEAN_ID);
  ExecutorService executor = Executors.newFixedThreadPool(putTakeThreadCount * 2);
  for(int i=0; i < putTakeThreadCount; ++i) {
    executor.submit(new PutData(finished, queue, dataCount));
    executor.submit(new TakeData(queue));
  }
  for(int i=0; i < pollCount; ++i) {
    queue.getAvgWait();
    queue.getAdded();
    queue.getCurrentSize();
    queue.getMaxWait();
    queue.getRemoved();
    queue.getThroughput();
  }
  finished.await();
  while(!queue.isEmpty()) {
    LOGGER.info("Waiting for queue to be emptied...");
    safeSleep(500);
  }
  long totalData = ((long) dataCount) * putTakeThreadCount;
  Assert.assertEquals(totalData, queue.getAdded());
  Assert.assertEquals(totalData, queue.getRemoved());
  executor.shutdown();
  executor.awaitTermination(1000, TimeUnit.MILLISECONDS); //shutdown puts
  executor.shutdownNow();
  executor.awaitTermination(1000, TimeUnit.MILLISECONDS); //shutdown takes
  //Randomized should not report thread leak
}
 
Example #26
Source File: LocalStreamBuilderTest.java    From streams with Apache License 2.0 5 votes vote down vote up
@Test
@Repeat(iterations = 3)
public void testBasicLinearStreamRandom()  {
  int numDatums = randomIntBetween(1, 100000);
  int numProcessors = randomIntBetween(1, 10);
  linearStreamNonParallel(numDatums, numProcessors);
}
 
Example #27
Source File: S2PrefixTreeTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
@Repeat(iterations = 10)
public void testCells() {
  int face = random().nextInt(6);
  S2CellId id = S2CellId.fromFacePosLevel(face, 0, 0);
  int arity = random().nextInt(3) + 1;
  int level = random().nextInt(S2PrefixTree.getMaxLevels(arity));
  level = level * arity;
  for (int i = 0; i < level; i++) {
    int pos = random().nextInt(4);
    id = id.childBegin();
    if (pos == 0) continue;
    id = id.next();
    if (pos == 1) continue;
    id = id.next();
    if (pos == 2) continue;
    id = id.next();
  }
  S2PrefixTree tree = new S2PrefixTree(new Geo3dSpatialContextFactory().newSpatialContext(), S2PrefixTree.getMaxLevels(arity), arity);
  S2PrefixTreeCell cell = new S2PrefixTreeCell(tree, id);
  BytesRef ref = cell.getTokenBytesWithLeaf(null);
  if (random().nextBoolean()) {
    int newOffset = random().nextInt(10) + 1;
    byte[] newBytes = new byte[ref.bytes.length +  newOffset];
    for (int i = 0; i < ref.bytes.length; i++) {
      newBytes[i + newOffset] = ref.bytes[i];
    }
    ref.bytes = newBytes;
    ref.offset = ref.offset + newOffset;
  }
  S2PrefixTreeCell cell2 = new S2PrefixTreeCell(tree, null);
  cell2.readCell(tree, ref);
  assertEquals(cell, cell2);
}
 
Example #28
Source File: TestMaxFailuresRule.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Repeat(iterations = TOTAL_ITERS)
public void testFailSometimes() {
  numIters++;
  boolean fail = random().nextInt(5) == 0;
  if (fail) numFails++;
  // some seeds are really lucky ... so cheat.
  if (numFails < DESIRED_FAILURES && 
      DESIRED_FAILURES <= TOTAL_ITERS - numIters) {
    fail = true;
  }
  assertFalse(fail);
}
 
Example #29
Source File: GeoExactCircleTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
@Repeat(iterations = 100)
public void RandomPointBearingWGS84Test(){
  PlanetModel planetModel = PlanetModel.WGS84;
  RandomGeo3dShapeGenerator generator = new RandomGeo3dShapeGenerator();
  GeoPoint center = generator.randomGeoPoint(planetModel);
  double radius = random().nextDouble() * Math.PI;
  checkBearingPoint(planetModel, center, radius, 0);
  checkBearingPoint(planetModel, center, radius, 0.5 * Math.PI);
  checkBearingPoint(planetModel, center, radius, Math.PI);
  checkBearingPoint(planetModel, center, radius, 1.5 * Math.PI);
}
 
Example #30
Source File: RandomBinaryCodecTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
@Repeat(iterations = 100)
public void testRandomShapeCodec() throws IOException{
  PlanetModel planetModel = randomPlanetModel();
  int type = randomShapeType();
  GeoShape shape = randomGeoShape(type, planetModel);
  ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  SerializableObject.writeObject(outputStream, shape);
  ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
  SerializableObject shapeCopy = SerializableObject.readObject(planetModel, inputStream);
  assertEquals(shape.toString(), shape, shapeCopy);
}