@Test public void testGetUserTaskLoad() { // Prepare and claim 6 tasks by The Emperor for (int x = 0; x < 6; x++) { TaskFluent task = new TaskFluent() .setName("CalculatorTask1") .addPotentialUser(DARTH_VADER) .setDeploymentID(DEPLOYMENT_ID) .setProcessId(PROCESS_ID) .setAdminUser(ADMIN); createTaskWithoutAssert(task); } User userVader = new UserImpl(DARTH_VADER); TaskContext ctx = new TaskContext(); EntityManager em = emf.createEntityManager(); ctx.setPersistenceContext(new JPATaskPersistenceContext(em)); LoadCalculator calculator = new TotalCompletionTimeLoadCalculator(); Double userTaskLoad = calculator.getUserTaskLoad(userVader, ctx).getCalculatedLoad(); Double userTaskLoads = calculator.getUserTaskLoads(Collections.singletonList(userVader), ctx).iterator().next().getCalculatedLoad(); Assertions.assertThat(userTaskLoad).isGreaterThanOrEqualTo(840.0); Assertions.assertThat(userTaskLoads).isEqualTo(userTaskLoad); em.close(); }
@Test public void subscribeToComplete() { Mono<Long> source = Mono.delay(Duration.ofMillis(100)) .hide(); new MonoMetrics<>(source, registry) .block(); Timer stcCompleteTimer = registry.find(METER_FLOW_DURATION) .tag(TAG_STATUS, TAGVALUE_ON_COMPLETE) .timer(); Timer stcErrorTimer = registry.find(METER_FLOW_DURATION) .tag(TAG_STATUS, TAGVALUE_ON_ERROR) .timer(); Timer stcCancelTimer = registry.find(METER_FLOW_DURATION) .tag(TAG_STATUS, TAGVALUE_CANCEL) .timer(); assertThat(stcCompleteTimer.max(TimeUnit.MILLISECONDS)) .as("subscribe to complete timer") .isGreaterThanOrEqualTo(100); assertThat(stcErrorTimer) .as("subscribe to error timer is lazily registered") .isNull(); assertThat(stcCancelTimer.max(TimeUnit.MILLISECONDS)) .as("subscribe to cancel timer") .isZero(); }
@Test public void testQuerySort() throws Exception { Random random = new Random(4711); for (int i = 0; i < 10; i++) { collection.insertOne(new Document("_id", Double.valueOf(random.nextDouble()))); } List<Document> objects = toArray(collection.find().sort(json("_id: 1"))); double before = Double.MIN_VALUE; for (Document obj : objects) { double value = obj.getDouble("_id").doubleValue(); assertThat(value).isGreaterThanOrEqualTo(before); before = value; } // reverse sort objects = toArray(collection.find().sort(json("_id: -1"))); before = Double.MAX_VALUE; for (Document obj : objects) { double value = obj.getDouble("_id").doubleValue(); assertThat(value).isLessThanOrEqualTo(before); before = value; } }
@DisplayName("multiple increments are maintained") @Test default void increment(MeterRegistry registry) { Counter c = registry.counter("myCounter"); c.increment(); clock(registry).add(step()); assertThat(c.count()).isEqualTo(1.0, offset(1e-12)); c.increment(); c.increment(); clock(registry).add(step()); // in the case of a step aggregating system will be 2, otherwise 3 assertThat(c.count()).isGreaterThanOrEqualTo(2.0); }
@Test(dataProvider = "onlyIfAutomaticHardwareSupported", groups = {"integration", "live"}) public void testAutoGeneratedHardwareWithOnlyMinCoresMatchHardwareProfile() { if (!view.getComputeService().listHardwareProfiles().isEmpty()) { Template template = view.getComputeService().templateBuilder().minCores(4).build(); assertThat(AutomaticHardwareIdSpec.isAutomaticId(template.getHardware().getId())).isFalse(); assertThat(template.getHardware().getProcessors().get(0).getCores()).isGreaterThanOrEqualTo(4); } else { throw new SkipException("Hardware profile list is empty, this provider can not match any hardware profile" + "to the specified minRam and minCores."); } }
@Test(dataProvider = "onlyIfAutomaticHardwareSupported", groups = {"integration", "live"}) public void testAutoGeneratedHardwareMatchHardwareProfile() { if (!view.getComputeService().listHardwareProfiles().isEmpty()) { Template template = view.getComputeService().templateBuilder() .minRam(2048).minCores(2).build(); assertThat(AutomaticHardwareIdSpec.isAutomaticId(template.getHardware().getId())).isFalse(); assertThat(template.getHardware().getRam()).isGreaterThanOrEqualTo(2048); assertThat(template.getHardware().getProcessors().get(0).getCores()).isGreaterThanOrEqualTo(2); } else { throw new SkipException("Hardware profile list is empty, this provider can not match any hardware profile" + "to the specified minRam and minCores."); } }
@Test public void testFilterPerformance() throws Exception { // Apply a filter operation and measure the elapsed time. long begin = System.nanoTime(); int lookupTimes = 1000; for (int i = 0; i < lookupTimes; i++) { dataSetOpEngine.execute(EXPENSE_REPORTS, filterByCityAndDept.getOperationList()); } long time = System.nanoTime() - begin; // Check out the resulting stats DataSetIndex dataSetIndex = dataSetOpEngine.getIndexRegistry().get(EXPENSE_REPORTS); DataSetIndexStats stats = dataSetIndex.getStats(); DataSet dataSet = dataSetIndex.getDataSet(); System.out.println(stats.toString("\n")); // Assert reuse is working. assertThat(stats.getNumberOfFilterOps()).isEqualTo(2); // The build time should be shorter than the overall lookup time. assertThat(stats.getBuildTime()).isLessThan(time); // The reuse rate must reflect the number of times the lookups are being reused. assertThat(stats.getReuseRate()).isGreaterThanOrEqualTo(lookupTimes - 1); // The index size must not be greater than the 20% of the dataset's size assertThat(stats.getIndexSize()).isLessThan(dataSet.getEstimatedSize() / 5); }
@Test public void testGroupPerformance() throws Exception { // Apply two different group operations and measure the elapsed time. long begin = System.nanoTime(); int lookupTimes = 1000; for (int i = 0; i < lookupTimes; i++) { dataSetOpEngine.execute(EXPENSE_REPORTS, groupByDeptAndCount.getOperationList()); dataSetOpEngine.execute(EXPENSE_REPORTS, groupByDeptAndSum.getOperationList()); } long time = System.nanoTime() - begin; // Check out the resulting stats DataSetIndex dataSetIndex = dataSetOpEngine.getIndexRegistry().get(EXPENSE_REPORTS); DataSetIndexStats stats = dataSetIndex.getStats(); DataSet dataSet = dataSetIndex.getDataSet(); System.out.println(stats.toString("\n")); // Assert the reuse of group operations and aggregate calculations is working. assertThat(stats.getNumberOfGroupOps()).isEqualTo(1); assertThat(stats.getNumberOfAggFunctions()).isEqualTo(10); // The build time should be shorter than the overall lookup time. assertThat(stats.getBuildTime()).isLessThan(time); // The reuse rate must reflect the number of times the lookups are being reused. assertThat(stats.getReuseRate()).isGreaterThanOrEqualTo(lookupTimes - 1); // The index size must not be greater than the 20% of the dataset's size assertThat(stats.getIndexSize()).isLessThan(dataSet.getEstimatedSize() / 5); }
assertThat(stats.getReuseRate()).isGreaterThanOrEqualTo(lookupTimes - 1);
@Test public void testGetUserTaskLoad() { // Prepare and claim 6 tasks by The Emperor for (int x = 0; x < 6; x++) { TaskFluent task = new TaskFluent() .setName("CalculatorTask1") .addPotentialUser(DARTH_VADER) .setDeploymentID(DEPLOYMENT_ID) .setProcessId(PROCESS_ID) .setAdminUser(ADMIN); createTaskWithoutAssert(task); } User userVader = new UserImpl(DARTH_VADER); TaskContext ctx = new TaskContext(); EntityManager em = emf.createEntityManager(); ctx.setPersistenceContext(new JPATaskPersistenceContext(em)); LoadCalculator calculator = new TotalCompletionTimeLoadCalculator(); Double userTaskLoad = calculator.getUserTaskLoad(userVader, ctx).getCalculatedLoad(); Double userTaskLoads = calculator.getUserTaskLoads(Collections.singletonList(userVader), ctx).iterator().next().getCalculatedLoad(); Assertions.assertThat(userTaskLoad).isGreaterThanOrEqualTo(840.0); Assertions.assertThat(userTaskLoads).isEqualTo(userTaskLoad); em.close(); }