@Test public void expectSuccessWithFile() throws Exception { final File file = folder.newFile(); assertThat(file.length()).isZero(); final KeyStore keyStore = KeyStore.getInstance("JKS"); keyStore.load(null, null); keyStore.store(new FileOutputStream(file), "".toCharArray()); assertThat(file.length()).isGreaterThan(0); assertThat(file.canRead()).isTrue(); assertThat(file.exists()).isTrue(); new KeyStoreCredentialResolverBuilder(file).build(); }
@Test public void index_nothing() { underTest.indexOnStartup(emptySet()); assertThat(es.countDocuments(INDEX_TYPE_PROJECT_MEASURES)).isZero(); }
@Test public void getPendingCount_returns_0_without_querying_database() { assertThat(underTest.getPendingCount()).isZero(); verifyZeroInteractions(getDbClient()); } }
@Test public void indexOnStartup_does_nothing_if_no_data() { underTest.indexOnStartup(emptySet()); assertThat(es.countDocuments(INDEX_TYPE_ACTIVE_RULE)).isZero(); }
@Test public void usedMemoryIsZeroOnDefault() { setUpSingleSlabManager(); assertThat(this.freeListManager.getUsedMemory()).isZero(); }
@Test public void freeTinyMemoryDefault() { setUpSingleSlabManager(); assertThat(this.freeListManager.getFreeTinyMemory()).isZero(); }
@Test public void untrackedMessageAreNotStored() throws Exception { // Nothing tracked assertThat(activeMessageHandler.getTrackedClients().count()).isZero(); List<Element> elements = new ArrayList<>(1); elements.add(getElement(createPayload(44L))); // Send a replace message, those are not tracked storeProxy.replaceAtHead(44L, getChain(elements), getChain(new ArrayList<>(0))); // Not tracked as well storeProxy.get(42L); assertThat(activeMessageHandler.getTrackedClients().count()).isZero(); }
@Test public void freeHugeMemoryDefault() { setUpSingleSlabManager(); assertThat(this.freeListManager.getFreeHugeMemory()).isZero(); }
@Test public void messageTrackedAndRemovedByPassiveWhenClientLeaves() throws Exception { assertThat(passiveMessageHandler.getTrackedClients().count()).isZero(); // nothing tracked right now storeProxy.getAndAppend(42L, createPayload(42L)); Map<Long, EhcacheEntityResponse> responses = passiveMessageHandler.getTrackedResponsesForSegment(KEY_ENDS_UP_IN_SEGMENT_11, passiveMessageHandler.getTrackedClients().findFirst().get()); assertThat(responses).hasSize(1); // should now track one message service.stop(); // stop the service. It will remove the client activeEntity.notifyDestroyed(passiveMessageHandler.getTrackedClients().iterator().next()); passiveEntity.notifyDestroyed(passiveMessageHandler.getTrackedClients().iterator().next()); // Notify that the client was removed. A real clustered server will do that. But the Passthrough doesn't. So we simulate it waitForPredicate(e -> activeEntity.getConnectedClients().size() > 0, 2000); // wait for the client to be removed, might be async, so we wait assertThat(passiveMessageHandler.getTrackedClients().count()).isZero(); // all tracked messages for this client should have been removed }
@Test public void maxAllocationUsesAllMemory() { setUpSingleSlabManager(); this.freeListManager.allocate(DEFAULT_SLAB_SIZE - 8); assertThat(this.freeListManager.getFreeMemory()).isZero(); assertThat(this.freeListManager.getUsedMemory()).isEqualTo(DEFAULT_SLAB_SIZE); }
@Test public void messageTrackedAndRemovedWhenClientLeaves() throws Exception { assertThat(activeMessageHandler.getTrackedClients().count()).isZero(); // no client tracked storeProxy.getAndAppend(42L, createPayload(42L)); Map<Long, EhcacheEntityResponse> responses = activeMessageHandler.getTrackedResponsesForSegment(KEY_ENDS_UP_IN_SEGMENT_11, activeMessageHandler.getTrackedClients().findFirst().get()); assertThat(responses).hasSize(1); // should now track one message assertThat(activeEntity.getConnectedClients()).hasSize(1); // make sure we currently have one client attached service.stop(); // stop the service. It will remove the client activeEntity.notifyDestroyed(activeMessageHandler.getTrackedClients().iterator().next()); // Notify that the client was removed. A real clustered server will do that. But the Passthrough doesn't. So we simulate it waitForPredicate(e -> activeEntity.getConnectedClients().size() > 0, 2000); // wait for the client to be removed, might be async, so we wait assertThat(activeMessageHandler.getTrackedClients().count()).isZero(); // all tracked messages for this client should have been removed }
@Test public void scanInnerGroupRequestNotTrackedWhenParent() { ParallelInnerGroup<Integer> test = new ParallelInnerGroup<>(1023); CoreSubscriber<Integer> subscriber = new LambdaSubscriber<>(null, e -> {}, null, sub -> sub.request(3)); Subscription s = Operators.emptySubscription(); test.onSubscribe(s); test.subscribe(subscriber); assertThat(test.scan(Scannable.Attr.REQUESTED_FROM_DOWNSTREAM)).isZero(); test.request(2); assertThat(test.scan(Scannable.Attr.REQUESTED_FROM_DOWNSTREAM)).isZero(); }
@Test public void freeFragmentMemoryMostOfFragmentAllocated() { setUpSingleSlabManager(); OffHeapStoredObject c = this.freeListManager.allocate(DEFAULT_SLAB_SIZE - 8 - 8); assertThat(this.freeListManager.getFreeFragmentMemory()).isZero(); }
@Test public void flushNoCallbackIncreaseBytes() { chain.increaseCallbackBytes(10L); chain.increaseCallbackBytes(6L); assertThat(chain.noCallbackIncreaseBytes).isEqualTo(16L); chain.flushNoCallbackIncreaseBytes(); verify(OkDownload.with().callbackDispatcher().dispatch()) .fetchProgress(eq(chain.getTask()), eq(0), eq(16L)); assertThat(chain.noCallbackIncreaseBytes).isZero(); }
@Test public void scanExecutorAttributes() { Scheduler fixedThreadPool = Schedulers.fromExecutorService(Executors.newFixedThreadPool(3)); Long test = Integer.MAX_VALUE + 1L; System.out.println(test.intValue() == Integer.MAX_VALUE); assertThat(Scannable.from(fixedThreadPool).scan(Scannable.Attr.CAPACITY)).isEqualTo(3); assertThat(Scannable.from(fixedThreadPool).scan(Scannable.Attr.BUFFERED)).isZero(); assertThat(Scannable.from(fixedThreadPool).scan(Scannable.Attr.LARGE_BUFFERED)).isZero(); fixedThreadPool.schedule(() -> { assertThat(Scannable.from(fixedThreadPool).scan(Scannable.Attr.BUFFERED)).isNotZero(); assertThat(Scannable.from(fixedThreadPool).scan(Scannable.Attr.LARGE_BUFFERED)).isNotZero(); }); } }
@Test public void do_not_return_external_rule() { db.rules().insert(r -> r.setIsExternal(true)); indexRules(); SearchResponse result = ws.newRequest().executeProtobuf(SearchResponse.class); assertThat(result.getTotal()).isZero(); assertThat(result.getRulesCount()).isZero(); }
@Test public void requestTrackingDisabledIfNotNamedFuseable() { Flux<Integer> source = Flux.range(1, 10); new FluxMetricsFuseable<>(source, registry) .blockLast(); DistributionSummary meter = registry.find(METER_REQUESTED) .summary(); if (meter != null) { //meter could be null in some tests assertThat(meter.count()).isZero(); } }
@Test public void requestTrackingDisabledIfNotNamed() { Flux<Integer> source = Flux.range(1, 10) .hide(); new FluxMetrics<>(source, registry) .blockLast(); DistributionSummary meter = registry.find(METER_REQUESTED) .summary(); if (meter != null) { //meter could be null in some tests assertThat(meter.count()).isZero(); } }
@Test public void do_not_persist_existing_external_rules() { RuleKey ruleKey = RuleKey.of("eslint", "no-cond-assign"); db.rules().insert(ruleKey, r -> r.setIsExternal(true)); ruleRepository.addOrUpdateAddHocRuleIfNeeded(ruleKey, () -> new NewAdHocRule(ScannerReport.ExternalIssue.newBuilder().setEngineId("eslint").setRuleId("no-cond-assign").build())); underTest.execute(new TestComputationStepContext()); RuleDao ruleDao = dbClient.ruleDao(); assertThat(ruleDao.selectAllDefinitions(dbClient.openSession(false))).hasSize(1); assertThat(es.countDocuments(RuleIndexDefinition.INDEX_TYPE_RULE)).isZero(); }