return anyMap();
private void verifyTokenIsNotUpdated() { verify(jwtHttpHandler, never()).generateToken(any(UserDto.class), anyMap(), any(HttpServletRequest.class), any(HttpServletResponse.class)); }
@Test public void executeQueryWithoutRetries() throws QueryExecutionKernelException { executionEngine.executeWithRetries( "query", Collections.emptyMap(), transactionalContext, executor ); verify( executor, times( 1 ) ).execute( any(), anyMap(), any() ); verify( versionContext, times( 1 ) ).initRead(); }
@Test public void executeQueryAfterSeveralRetries() throws QueryExecutionKernelException { when( versionContext.isDirty() ).thenReturn( true, true, false ); executionEngine.executeWithRetries( "query", Collections.emptyMap(), transactionalContext, executor ); verify( executor, times( 3 ) ).execute( any(), anyMap(), any() ); verify( versionContext, times( 3 ) ).initRead(); }
@Test public void settings_should_include_command_line_args_with_highest_priority() { when(globalConfiguration.getProperties()).thenReturn(Collections.singletonMap("key", "global")); when(projectServerSettings.properties()).thenReturn(Collections.singletonMap("key", "settings")); when(root.properties()).thenReturn(Collections.singletonMap("key", "root")); provider.provide(loader, globalConfiguration, reactor, globalServerSettings, projectServerSettings, branches, pullRequests); verify(loader).load(anyMap(), settingsCaptor.capture(), any(ProjectBranches.class), any(ProjectPullRequests.class)); Map<String, String> map = settingsCaptor.getValue().get(); assertThat(map.get("key")).isEqualTo("root"); }
@Test public void execute() throws Exception { doNothing().when(redirectHandler).handleRedirect(any(DownloadConnection.class), any(DownloadConnection.Connected.class), ArgumentMatchers.<String, List<String>>anyMap()); downloadUrlConnection.execute(); verify(urlConnection).connect(); }
@Before public void setUp() throws Exception { GraphDatabaseQueryService cypherService = new GraphDatabaseCypherService( this.database.getGraphDatabaseAPI() ); compilerFactory = mock( CompilerFactory.class ); transactionalContext = mock( TransactionalContext.class ); KernelStatement kernelStatement = mock( KernelStatement.class ); executor = mock( SnapshotExecutionEngine.ParametrizedQueryExecutor.class ); versionContext = mock( VersionContext.class ); executionEngine = createExecutionEngine(cypherService); when( kernelStatement.getVersionContext() ).thenReturn( versionContext ); when( transactionalContext.statement() ).thenReturn( kernelStatement ); Result result = mock( Result.class ); QueryStatistics statistics = mock( QueryStatistics.class ); when( result.getQueryStatistics() ).thenReturn( statistics ); when( executor.execute( any(), anyMap(), any() ) ).thenReturn( result ); }
@Test public void failQueryAfterMaxRetriesReached() throws QueryExecutionKernelException { when( versionContext.isDirty() ).thenReturn( true ); try { executionEngine.executeWithRetries( "query", Collections.emptyMap(), transactionalContext, executor ); } catch ( QueryExecutionKernelException e ) { assertEquals( "Unable to get clean data snapshot for query 'query' after 5 attempts.", e.getMessage() ); } verify( executor, times( 5 ) ).execute( any(), anyMap(), any() ); verify( versionContext, times( 5 ) ).initRead(); }
@Test public void submit_task_to_the_queue_and_ask_for_immediate_processing() { when(reportSubmitter.submit(eq(organizationKey), eq("my_project"), isNull(), eq("My Project"), anyMap(), any())).thenReturn(A_CE_TASK); Ce.SubmitResponse submitResponse = tester.newRequest() .setParam("projectKey", "my_project") .setParam("projectName", "My Project") .setPart("report", new ByteArrayInputStream("{binary}".getBytes()), "foo.bar") .setMethod("POST") .executeProtobuf(Ce.SubmitResponse.class); verify(reportSubmitter).submit(eq(organizationKey), eq("my_project"), isNull(), eq("My Project"), anyMap(), any()); assertThat(submitResponse.getTaskId()).isEqualTo("TASK_1"); assertThat(submitResponse.getProjectId()).isEqualTo(PROJECT_UUID); }
@Test public void shouldReportIndexExistsWithMatchingConfiguration() { // given ExplicitIndexTransactionStateImpl state = newExplicitIndexTxState(); when( provider.configMatches( anyMap(), anyMap() ) ).thenReturn( true ); // when boolean nodeExists = state.checkIndexExistence( IndexEntityType.Node, "name", config ); boolean relExists = state.checkIndexExistence( IndexEntityType.Node, "name", config ); // then assertTrue( nodeExists ); assertTrue( relExists ); }
/** * If project name is not specified, then name is the project key */ @Test public void project_name_is_optional() { when(reportSubmitter.submit(eq(organizationKey), eq("my_project"), isNull(), eq("my_project"), anyMap(), any())).thenReturn(A_CE_TASK); tester.newRequest() .setParam("projectKey", "my_project") .setPart("report", new ByteArrayInputStream("{binary}".getBytes()), "foo.bar") .setMediaType(MediaTypes.PROTOBUF) .setMethod("POST") .execute(); verify(reportSubmitter).submit(eq(organizationKey), eq("my_project"), isNull(), eq("my_project"), anyMap(), any()); } }
@Test public void submit_task_with_characteristics() { when(reportSubmitter.submit(eq(organizationKey), eq("my_project"), isNull(), eq("My Project"), anyMap(), any())).thenReturn(A_CE_TASK); String[] characteristics = {"branch=foo", "pullRequest=123", "unsupported=bar"}; Ce.SubmitResponse submitResponse = tester.newRequest() .setParam("projectKey", "my_project") .setParam("projectName", "My Project") .setMultiParam("characteristic", asList(characteristics)) .setPart("report", new ByteArrayInputStream("{binary}".getBytes()), "foo.bar") .setMethod("POST") .executeProtobuf(Ce.SubmitResponse.class); assertThat(submitResponse.getTaskId()).isEqualTo("TASK_1"); verify(reportSubmitter).submit(eq(organizationKey), eq("my_project"), isNull(), eq("My Project"), map.capture(), any()); // unsupported characteristics are ignored assertThat(map.getValue()).containsExactly(entry("branch", "foo"), entry("pullRequest", "123")); }
@Test public void shouldThrowOnIndexExistsWithMismatchingConfiguration() { // given ExplicitIndexTransactionStateImpl state = newExplicitIndexTxState(); when( provider.configMatches( anyMap(), anyMap() ) ).thenReturn( false ); // when try { state.checkIndexExistence( IndexEntityType.Node, "name", config ); fail( "Should've failed" ); } catch ( IllegalArgumentException e ) { // then good } try { state.checkIndexExistence( IndexEntityType.Node, "name", config ); fail( "Should have failed" ); } catch ( IllegalArgumentException e ) { // then good } }
@Test public void install_and_load_plugins() { PluginInfo info = new PluginInfo("squid"); ImmutableMap<String, ScannerPlugin> plugins = ImmutableMap.of("squid", new ScannerPlugin("squid", 1L, info)); Plugin instance = mock(Plugin.class); when(loader.load(anyMap())).thenReturn(ImmutableMap.of("squid", instance)); when(installer.installRemotes()).thenReturn(plugins); underTest.start(); assertThat(underTest.getPluginInfos()).containsOnly(info); assertThat(underTest.getPluginsByKey()).isEqualTo(plugins); assertThat(underTest.getPluginInfo("squid")).isSameAs(info); assertThat(underTest.getPluginInstance("squid")).isSameAs(instance); underTest.stop(); verify(loader).unload(anyCollection()); }
@Test public void test_example_json_response() { when(reportSubmitter.submit(eq(organizationKey), eq("my_project"), isNull(), eq("My Project"), anyMap(), any())).thenReturn(A_CE_TASK); TestResponse wsResponse = tester.newRequest() .setParam("projectKey", "my_project") .setParam("projectName", "My Project") .setPart("report", new ByteArrayInputStream("{binary}".getBytes()), "foo.bar") .setMediaType(MediaTypes.JSON) .setMethod("POST") .execute(); JsonAssert.assertJson(tester.getDef().responseExampleAsString()).isSimilarTo(wsResponse.getInput()); }
@Test public void sweepCellOnlyOnceWhenInLastPartitionBeforeSweepTs() { immutableTs = 2 * TS_COARSE_GRANULARITY - TS_FINE_GRANULARITY; verify(spiedKvs, never()).deleteAllTimestamps(any(TableReference.class), anyMap(), eq(false)); enqueueWriteCommitted(TABLE_CONS, immutableTs - 1); sweepQueue.sweepNextBatch(ShardAndStrategy.conservative(CONS_SHARD)); verify(spiedKvs, times(1)).deleteAllTimestamps(any(TableReference.class), anyMap(), eq(false)); sweepQueue.sweepNextBatch(ShardAndStrategy.conservative(CONS_SHARD)); verify(spiedKvs, times(1)).deleteAllTimestamps(any(TableReference.class), anyMap(), eq(false)); }
@Test public void sweepStrategyNothingDoesNotPersistAnything() { enqueueWriteCommitted(TABLE_NOTH, LOW_TS); enqueueWriteCommitted(TABLE_NOTH, LOW_TS2); verify(spiedKvs, times(2)).put(eq(TABLE_NOTH), anyMap(), anyLong()); verify(spiedKvs, times(2)).put(any(TableReference.class), anyMap(), anyLong()); }
@Test public void progressivelyFailingCasEventuallySucceeds() { KeyValueService mockKvs = mock(KeyValueService.class); when(mockKvs.get(any(), anyMap())) .thenReturn(ImmutableMap.of()) .thenReturn(ImmutableMap.of(DUMMY, createValue(5L))) .thenReturn(ImmutableMap.of(DUMMY, createValue(10L))) .thenReturn(ImmutableMap.of(DUMMY, createValue(15L))); doThrow(new CheckAndSetException("sadness")).when(mockKvs).checkAndSet(any()); ShardProgress instrumentedProgress = new ShardProgress(mockKvs); assertThat(instrumentedProgress.updateLastSweptTimestamp(CONSERVATIVE_TEN, 12L)) .isEqualTo(15L); }
@Test public void thoroughSweepDeletesAllButLatestWithSingleDeleteAllTimestampsIncludingSentinels() { long lastWriteTs = TS_FINE_GRANULARITY - 1; for (long i = 1; i <= lastWriteTs; i++) { enqueueWriteCommitted(TABLE_THOR, i); } sweepQueue.sweepNextBatch(ShardAndStrategy.thorough(THOR_SHARD)); assertReadAtTimestampReturnsNothing(TABLE_THOR, lastWriteTs); assertTestValueEnqueuedAtGivenTimestampStillPresent(TABLE_THOR, lastWriteTs); verify(spiedKvs, times(1)).deleteAllTimestamps(any(TableReference.class), anyMap(), eq(true)); }
@Test public void conservativeSweepDeletesAllButLatestWithSingleDeleteAllTimestamps() { long lastWriteTs = TS_FINE_GRANULARITY - 1; for (long i = 1; i <= lastWriteTs; i++) { enqueueWriteCommitted(TABLE_CONS, i); } sweepQueue.sweepNextBatch(ShardAndStrategy.conservative(CONS_SHARD)); assertReadAtTimestampReturnsSentinel(TABLE_CONS, lastWriteTs); assertTestValueEnqueuedAtGivenTimestampStillPresent(TABLE_CONS, lastWriteTs); verify(spiedKvs, times(1)).deleteAllTimestamps(any(TableReference.class), anyMap(), eq(false)); }