@Test public void noRetentionOnTerminationError() throws InterruptedException { CompletableFuture<Date> future = new CompletableFuture<>(); WeakReference<CompletableFuture<Date>> refFuture = new WeakReference<>(future); Mono<Date> source = Mono.fromFuture(future); Mono<String> data = source.map(Date::toString).cache(); future.completeExceptionally(new IllegalStateException()); assertThatExceptionOfType(IllegalStateException.class) .isThrownBy(data::block); future = null; source = null; System.gc(); int cycles; for (cycles = 10; cycles > 0 ; cycles--) { if (refFuture.get() == null) break; Thread.sleep(100); } assertThat(refFuture.get()).isNull(); assertThat(cycles).isNotZero() .isPositive(); }
@Test public void noRetentionOnTermination() throws InterruptedException { Date date = new Date(); CompletableFuture<Date> future = new CompletableFuture<>(); WeakReference<Date> refDate = new WeakReference<>(date); WeakReference<CompletableFuture<Date>> refFuture = new WeakReference<>(future); Mono<Date> source = Mono.fromFuture(future); Mono<String> data = source.map(Date::toString).log().cache().log(); future.complete(date); assertThat(data.block()).isEqualTo(date.toString()); date = null; future = null; source = null; System.gc(); int cycles; for (cycles = 10; cycles > 0 ; cycles--) { if (refDate.get() == null && refFuture.get() == null) break; Thread.sleep(100); } assertThat(refFuture.get()).isNull(); assertThat(refDate.get()).isNull(); assertThat(cycles).isNotZero() .isPositive(); }
@Test public void noRetentionOnTerminationCancel() throws InterruptedException { CompletableFuture<Date> future = new CompletableFuture<>(); WeakReference<CompletableFuture<Date>> refFuture = new WeakReference<>(future); Mono<Date> source = Mono.fromFuture(future); Mono<String> data = source.map(Date::toString).cache(); future = null; source = null; data.subscribe().dispose(); System.gc(); int cycles; for (cycles = 10; cycles > 0 ; cycles--) { if (refFuture.get() == null) break; Thread.sleep(100); } assertThat(refFuture.get()).isNull(); assertThat(cycles).isNotZero() .isPositive(); }
private void verifyActiveRuleInDb(QProfileDto profile, RuleDefinitionDto rule, String expectedSeverity) { ActiveRuleDto activeRule = db.getDbClient().activeRuleDao().selectByKey(dbSession, ActiveRuleKey.of(profile, rule.getKey())).get(); assertThat(activeRule.getId()).isPositive(); assertThat(activeRule.getInheritance()).isNull(); assertThat(activeRule.doesOverride()).isFalse(); assertThat(activeRule.getRuleId()).isEqualTo(rule.getId()); assertThat(activeRule.getProfileId()).isEqualTo(profile.getId()); assertThat(activeRule.getSeverityString()).isEqualTo(expectedSeverity); assertThat(activeRule.getCreatedAt()).isPositive(); assertThat(activeRule.getUpdatedAt()).isPositive(); List<ActiveRuleParamDto> params = db.getDbClient().activeRuleDao().selectParamsByActiveRuleId(dbSession, activeRule.getId()); assertThat(params).isEmpty(); QProfileChangeQuery changeQuery = new QProfileChangeQuery(profile.getKee()); QProfileChangeDto change = db.getDbClient().qProfileChangeDao().selectByQuery(dbSession, changeQuery).stream() .filter(c -> c.getDataAsMap().get("ruleId").equals(String.valueOf(rule.getId()))) .findFirst() .get(); assertThat(change.getChangeType()).isEqualTo(ActiveRuleChange.Type.ACTIVATED.name()); assertThat(change.getCreatedAt()).isPositive(); assertThat(change.getUuid()).isNotEmpty(); assertThat(change.getUserUuid()).isNull(); assertThat(change.getRulesProfileUuid()).isEqualTo(profile.getRulesProfileUuid()); assertThat(change.getDataAsMap().get("severity")).isEqualTo(expectedSeverity); }
assertThat(cause.getStackTrace()[0].getFileName()) .isEqualTo("GrpcStatusCauseTest.java"); assertThat(cause.getStackTrace()[0].getLineNumber()).isPositive();
@Test public void forwardedForIp() { testClientRequest( clientRequestHeaders -> clientRequestHeaders.add("Forwarded", "for=192.0.2.60;proto=http;by=203.0.113.43"), serverRequest -> { Assertions.assertThat(serverRequest.remoteAddress().getHostString()).isEqualTo("192.0.2.60"); Assertions.assertThat(serverRequest.remoteAddress().getPort()).isPositive(); Assertions.assertThat(serverRequest.scheme()).isEqualTo("http"); }); }
@Test public void forwardedForHostname() { testClientRequest( clientRequestHeaders -> clientRequestHeaders.add("Forwarded", "for=\"_gazonk\""), serverRequest -> { Assertions.assertThat(serverRequest.remoteAddress().getHostString()).isEqualTo("_gazonk"); Assertions.assertThat(serverRequest.remoteAddress().getPort()).isPositive(); }); }
@BeforeEach final void initServer() throws Exception { if (server == null) { server = new Server(); server.addConnector(new ServerConnector(server)); ServletContextHandler handler = new ServletContextHandler(); setUpHandler(handler); server.setHandler(handler); server.start(); } assertThat(getPort()).isPositive(); httpClient = new OkHttpClient.Builder() // set to 0 for debugging .readTimeout(10, TimeUnit.SECONDS) .connectTimeout(10, TimeUnit.SECONDS) .retryOnConnectionFailure(false) .build(); }
@Test public void comparatorWorksWithObjects() { Integer a = 1; Integer b = 2; assertThat(comparator.compare(a, b)).isNegative(); assertThat(comparator.compare(b, a)).isPositive(); }
@Test public void comparatorIsCaseInsensitive() { String a = "B1"; String b = "b2"; assertThat(comparator.compare(a, b)).isNegative(); assertThat(comparator.compare(b, a)).isPositive(); }
@Test public void comparatorWorksWithSameCase() { String a = "b1"; String b = "b2"; assertThat(comparator.compare(a, b)).isNegative(); assertThat(comparator.compare(b, a)).isPositive(); }
@Test @SuppressWarnings("unchecked") public void overviewListShouldAugmentWithConnectionUsageNoIntegrations() { ListResult<Connection> connectionResult = new ListResult.Builder<Connection>().addItem(c1, c2, c3).build(); when(dataManager.fetchAll(eq(Connection.class), any())).thenReturn(connectionResult); when(dataManager.fetchAll(Integration.class)).thenReturn(new ListResult.Builder<Integration>().build()); UriInfo uriInfo = mock(UriInfo.class); MultivaluedMap<String, String> params = mock(MultivaluedMap.class); when(uriInfo.getQueryParameters()).thenReturn(params); ListResult<ConnectionOverview> overviewResult = handler.list(uriInfo); assertNotNull(overviewResult); assertThat(overviewResult.getTotalCount()).isPositive(); List<ConnectionOverview> items = overviewResult.getItems(); for (int i = 0; i < items.size(); ++i) { ConnectionOverview overview = items.get(i); OptionalInt uses = overview.getUses(); assertThat(uses.isPresent()).isTrue(); assertThat(uses.getAsInt()).isZero(); } }
assertThat(isInetAddress(ping.getTo().getHost())).isTrue(); assertThat(isInetAddress(ping.getFrom().getHost())).isTrue(); assertThat(ping.getTo().getUdpPort()).isPositive(); assertThat(ping.getFrom().getUdpPort()).isPositive(); ping.getTo().getTcpPort().ifPresent(p -> assertThat(p).isPositive()); ping.getFrom().getTcpPort().ifPresent(p -> assertThat(p).isPositive()); assertThat(ping.getExpiration()).isPositive(); break; assertThat(pong.getTo().getUdpPort()).isPositive(); pong.getTo().getTcpPort().ifPresent(p -> assertThat(p).isPositive()); assertThat(pong.getPingHash().extractArray()).hasSize(32); assertThat(pong.getExpiration()).isPositive();