Skip to content

Commit

Permalink
Update spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
breskeby committed Oct 18, 2024
1 parent cae6add commit c9fb15a
Show file tree
Hide file tree
Showing 13 changed files with 252 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ develocity {
publishing.onlyIf { false }
}

def fips = buildParams.inFipsJvm
def gitRevision = buildParams.gitRevision

background {
tag OS.current().name()
tag Architecture.current().name()

// Tag if this build is run in FIPS mode
if (buildParams.inFipsJvm) {
if (fips) {
tag 'FIPS'
}

Expand Down Expand Up @@ -91,8 +94,8 @@ develocity {
link 'Source', "${prBaseUrl}/tree/${System.getenv('BUILDKITE_COMMIT')}"
link 'Pull Request', "https://github.com/${repository}/pull/${prId}"
} else {
value 'Git Commit ID', buildParams.gitRevision
link 'Source', "https://github.com/${repository}/tree/${buildParams.gitRevision}"
value 'Git Commit ID', gitRevision
link 'Source', "https://github.com/${repository}/tree/${gitRevision}"
}

buildFinished { result ->
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ org.gradle.welcome=never
org.gradle.warning.mode=none
org.gradle.parallel=true
# We need to declare --add-exports to make spotless working seamlessly with jdk16
org.gradle.jvmargs=-XX:+HeapDumpOnOutOfMemoryError -Xss2m --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
org.gradle.jvmargs=-XX:+HeapDumpOnOutOfMemoryError -Xss2m --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-opens java.base/java.time=ALL-UNNAMED

# Enforce the build to fail on deprecated gradle api usage
systemProp.org.gradle.warning.mode=fail
Expand Down
2 changes: 1 addition & 1 deletion gradle/build.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ snakeyaml = { group = "org.yaml", name = "snakeyaml", version = { strictly = "2.
spock-core = { group = "org.spockframework", name="spock-core", version.ref="spock" }
spock-junit4 = { group = "org.spockframework", name="spock-junit4", version.ref="spock" }
spock-platform = { group = "org.spockframework", name="spock-bom", version.ref="spock" }
spotless-plugin = "com.diffplug.spotless:spotless-plugin-gradle:6.25.0"
spotless-plugin = "com.diffplug.spotless:spotless-plugin-gradle:7.0.0.BETA3"
wiremock = "com.github.tomakehurst:wiremock-jre8-standalone:2.23.2"
xmlunit-core = "org.xmlunit:xmlunit-core:2.8.2"
130 changes: 130 additions & 0 deletions gradle/verification-metadata.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,26 @@ public void setUp() throws Exception {
}

public void testCanRegisterTwoRepositoriesWithDifferentTypes() {
when(plugin1.getRepositories(eq(environment), eq(contentRegistry), eq(clusterService),
eq(MockBigArrays.NON_RECYCLING_INSTANCE), eq(recoverySettings),
any(RepositoriesMetrics.class)))
.thenReturn(Collections.singletonMap("type1", factory));
when(plugin2.getRepositories(eq(environment), eq(contentRegistry), eq(clusterService),
eq(MockBigArrays.NON_RECYCLING_INSTANCE), eq(recoverySettings),
any(RepositoriesMetrics.class)))
.thenReturn(Collections.singletonMap("type2", factory));
when(
plugin1.getRepositories(
eq(environment),
eq(contentRegistry),
eq(clusterService),
eq(MockBigArrays.NON_RECYCLING_INSTANCE),
eq(recoverySettings),
any(RepositoriesMetrics.class)
)
).thenReturn(Collections.singletonMap("type1", factory));
when(
plugin2.getRepositories(
eq(environment),
eq(contentRegistry),
eq(clusterService),
eq(MockBigArrays.NON_RECYCLING_INSTANCE),
eq(recoverySettings),
any(RepositoriesMetrics.class)
)
).thenReturn(Collections.singletonMap("type2", factory));

// Would throw
new RepositoriesModule(
Expand All @@ -83,18 +95,32 @@ public void testCanRegisterTwoRepositoriesWithDifferentTypes() {
mock(ClusterService.class),
MockBigArrays.NON_RECYCLING_INSTANCE,
contentRegistry,
recoverySettings, TelemetryProvider.NOOP);
recoverySettings,
TelemetryProvider.NOOP
);
}

public void testCannotRegisterTwoRepositoriesWithSameTypes() {
when(plugin1.getRepositories(eq(environment), eq(contentRegistry), eq(clusterService),
eq(MockBigArrays.NON_RECYCLING_INSTANCE), eq(recoverySettings),
any(RepositoriesMetrics.class)))
.thenReturn(Collections.singletonMap("type1", factory));
when(plugin2.getRepositories(eq(environment), eq(contentRegistry), eq(clusterService),
eq(MockBigArrays.NON_RECYCLING_INSTANCE), eq(recoverySettings),
any(RepositoriesMetrics.class)))
.thenReturn(Collections.singletonMap("type1", factory));
when(
plugin1.getRepositories(
eq(environment),
eq(contentRegistry),
eq(clusterService),
eq(MockBigArrays.NON_RECYCLING_INSTANCE),
eq(recoverySettings),
any(RepositoriesMetrics.class)
)
).thenReturn(Collections.singletonMap("type1", factory));
when(
plugin2.getRepositories(
eq(environment),
eq(contentRegistry),
eq(clusterService),
eq(MockBigArrays.NON_RECYCLING_INSTANCE),
eq(recoverySettings),
any(RepositoriesMetrics.class)
)
).thenReturn(Collections.singletonMap("type1", factory));

IllegalArgumentException ex = expectThrows(
IllegalArgumentException.class,
Expand All @@ -106,7 +132,9 @@ public void testCannotRegisterTwoRepositoriesWithSameTypes() {
clusterService,
MockBigArrays.NON_RECYCLING_INSTANCE,
contentRegistry,
recoverySettings, TelemetryProvider.NOOP)
recoverySettings,
TelemetryProvider.NOOP
)
);

assertEquals("Repository type [type1] is already registered", ex.getMessage());
Expand All @@ -130,17 +158,25 @@ public void testCannotRegisterTwoInternalRepositoriesWithSameTypes() {
clusterService,
MockBigArrays.NON_RECYCLING_INSTANCE,
contentRegistry,
recoverySettings, TelemetryProvider.NOOP)
recoverySettings,
TelemetryProvider.NOOP
)
);

assertEquals("Internal repository type [type1] is already registered", ex.getMessage());
}

public void testCannotRegisterNormalAndInternalRepositoriesWithSameTypes() {
when(plugin1.getRepositories(eq(environment), eq(contentRegistry), eq(clusterService),
eq(MockBigArrays.NON_RECYCLING_INSTANCE), eq(recoverySettings),
any(RepositoriesMetrics.class)))
.thenReturn(Collections.singletonMap("type1", factory));
when(
plugin1.getRepositories(
eq(environment),
eq(contentRegistry),
eq(clusterService),
eq(MockBigArrays.NON_RECYCLING_INSTANCE),
eq(recoverySettings),
any(RepositoriesMetrics.class)
)
).thenReturn(Collections.singletonMap("type1", factory));
when(plugin2.getInternalRepositories(environment, contentRegistry, clusterService, recoverySettings)).thenReturn(
Collections.singletonMap("type1", factory)
);
Expand All @@ -155,7 +191,9 @@ public void testCannotRegisterNormalAndInternalRepositoriesWithSameTypes() {
clusterService,
MockBigArrays.NON_RECYCLING_INSTANCE,
contentRegistry,
recoverySettings, TelemetryProvider.NOOP)
recoverySettings,
TelemetryProvider.NOOP
)
);

assertEquals("Internal repository type [type1] is already registered as a non-internal repository", ex.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ public void testValidate_ServiceThrowsException() {
any()
);

assertThrows(ElasticsearchStatusException.class, () -> {
underTest.validate(mockInferenceService, mockModel, mockActionListener);});
assertThrows(
ElasticsearchStatusException.class,
() -> { underTest.validate(mockInferenceService, mockModel, mockActionListener); }
);

verifyCallToService(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,20 @@ public void testRunJob_TaskIsStopping() {
when(task.isStopping()).thenReturn(true);
when(task.getParams()).thenReturn(new StartDataFrameAnalyticsAction.TaskParams("data_frame_id", MlConfigVersion.CURRENT, false));

processManager.runJob(task, dataFrameAnalyticsConfig, dataExtractorFactory,
processManager.runJob(
task,
dataFrameAnalyticsConfig,
dataExtractorFactory,
ActionTestUtils.assertNoFailureListener(stepResponse -> {
assertThat(processManager.getProcessContextCount(), equalTo(0));
assertThat(stepResponse.isTaskComplete(), is(true));
assertThat(processManager.getProcessContextCount(), equalTo(0));
assertThat(stepResponse.isTaskComplete(), is(true));

InOrder inOrder = inOrder(task);
inOrder.verify(task).isStopping();
inOrder.verify(task).getParams();
verifyNoMoreInteractions(task);
}));
InOrder inOrder = inOrder(task);
inOrder.verify(task).isStopping();
inOrder.verify(task).getParams();
verifyNoMoreInteractions(task);
})
);
}

public void testRunJob_ProcessContextAlreadyExists() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ public void testInvalidateTokensWhenIndexUnavailable() throws Exception {
when(securityIndex.isAvailable(SecurityIndexManager.Availability.SEARCH_SHARDS)).thenReturn(false);
when(securityIndex.indexExists()).thenReturn(true);
when(securityIndex.defensiveCopy()).thenReturn(securityIndex);
when(securityIndex.getUnavailableReason(SecurityIndexManager.Availability.PRIMARY_SHARDS))
.thenReturn(new ElasticsearchException("simulated"));
when(securityIndex.getUnavailableReason(SecurityIndexManager.Availability.PRIMARY_SHARDS)).thenReturn(
new ElasticsearchException("simulated")
);
final TokenService tokenService = new TokenService(
SETTINGS,
Clock.systemUTC(),
Expand All @@ -102,8 +103,11 @@ public void testInvalidateTokensWhenIndexUnavailable() throws Exception {

Tuple<byte[], byte[]> newTokenBytes = tokenService.getRandomTokenBytes(true);
InvalidateTokenRequest request = new InvalidateTokenRequest(
tokenService.prependVersionAndEncodeAccessToken(TransportVersion.current(), newTokenBytes.v1()),
ACCESS_TOKEN.getValue(), null, null);
tokenService.prependVersionAndEncodeAccessToken(TransportVersion.current(), newTokenBytes.v1()),
ACCESS_TOKEN.getValue(),
null,
null
);
PlainActionFuture<InvalidateTokenResponse> accessTokenfuture = new PlainActionFuture<>();
action.doExecute(null, request, accessTokenfuture);
ElasticsearchSecurityException ese = expectThrows(ElasticsearchSecurityException.class, accessTokenfuture::actionGet);
Expand Down Expand Up @@ -148,8 +152,11 @@ public void testInvalidateTokensWhenIndexClosed() throws Exception {

Tuple<byte[], byte[]> newTokenBytes = tokenService.getRandomTokenBytes(true);
InvalidateTokenRequest request = new InvalidateTokenRequest(
tokenService.prependVersionAndEncodeAccessToken(TransportVersion.current(), newTokenBytes.v1()),
ACCESS_TOKEN.getValue(), null, null);
tokenService.prependVersionAndEncodeAccessToken(TransportVersion.current(), newTokenBytes.v1()),
ACCESS_TOKEN.getValue(),
null,
null
);
PlainActionFuture<InvalidateTokenResponse> accessTokenfuture = new PlainActionFuture<>();
action.doExecute(null, request, accessTokenfuture);
ElasticsearchSecurityException ese = expectThrows(ElasticsearchSecurityException.class, accessTokenfuture::actionGet);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2041,8 +2041,14 @@ public void testExpiredToken() throws Exception {
.user(new User("creator"))
.realmRef(new RealmRef("test", "test", "test"))
.build(false);
tokenService.createOAuth2Tokens(newTokenBytes.v1(), newTokenBytes.v2(), expected, originatingAuth, Collections.emptyMap(),
tokenFuture);
tokenService.createOAuth2Tokens(
newTokenBytes.v1(),
newTokenBytes.v2(),
expected,
originatingAuth,
Collections.emptyMap(),
tokenFuture
);
}
String token = tokenFuture.get().getAccessToken();
mockGetTokenFromAccessTokenBytes(tokenService, newTokenBytes.v1(), expected, Map.of(), true, null, client);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,13 @@ public void init() throws Exception {
}

public void testAuthenticateThrowsOnUnsupportedMinVersions() throws IOException {
when(clusterService.state().getMinTransportVersion()).thenReturn(TransportVersionUtils.randomVersionBetween(
when(clusterService.state().getMinTransportVersion()).thenReturn(
TransportVersionUtils.randomVersionBetween(
random(),
TransportVersions.MINIMUM_COMPATIBLE,
TransportVersionUtils.getPreviousVersion(TRANSPORT_VERSION_ADVANCED_REMOTE_CLUSTER_SECURITY)
));
)
);
final var authcContext = mock(Authenticator.Context.class, Mockito.RETURNS_DEEP_STUBS);
when(authcContext.getThreadContext()).thenReturn(threadContext);
final var crossClusterAccessHeaders = new CrossClusterAccessHeaders(
Expand All @@ -93,12 +95,14 @@ public void testAuthenticateThrowsOnUnsupportedMinVersions() throws IOException
when(auditableRequest.exceptionProcessingRequest(any(), any())).thenAnswer(
i -> new ElasticsearchSecurityException("potato", (Exception) i.getArguments()[0])
);
doAnswer(invocationOnMock -> new Authenticator.Context(
doAnswer(
invocationOnMock -> new Authenticator.Context(
threadContext,
auditableRequest,
mock(Realms.class),
(AuthenticationToken) invocationOnMock.getArguments()[2]
)).when(authenticationService).newContext(anyString(), any(), any());
)
).when(authenticationService).newContext(anyString(), any(), any());

final PlainActionFuture<Authentication> future = new PlainActionFuture<>();
crossClusterAccessAuthenticationService.authenticate("action", mock(TransportRequest.class), future);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ public void testRecordingFailedAuthenticationMetric() {
@SuppressWarnings("unchecked")
final ActionListener<AuthenticationResult<User>> listener = (ActionListener<AuthenticationResult<User>>) invocationOnMock
.getArguments()[1];
listener.onResponse(AuthenticationResult.unsuccessful("unsuccessful realms authentication", null));
listener.onResponse(AuthenticationResult.unsuccessful("unsuccessful realms authentication", null));
return null;
}).when(unsuccessfulRealm).authenticate(eq(authenticationToken), any());

Expand All @@ -337,7 +337,7 @@ public void testRecordingFailedAuthenticationMetric() {

final PlainActionFuture<AuthenticationResult<Authentication>> future = new PlainActionFuture<>();
realmsAuthenticator.authenticate(context, future);
var e = expectThrows(ElasticsearchSecurityException.class, () -> future.actionGet());
var e = expectThrows(ElasticsearchSecurityException.class, () -> future.actionGet());
assertThat(e, sameInstance(exception));

assertSingleFailedAuthMetric(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,7 @@ public void testGetPrivilegesWillOnlyWaitOnUnavailableShardException() {
public void testGetPrivilegesFailsAfterWaitOnUnavailableShardException() {
when(securityIndex.isAvailable(SecurityIndexManager.Availability.SEARCH_SHARDS)).thenReturn(false).thenReturn(false);

when(securityIndex.getUnavailableReason(SecurityIndexManager.Availability.SEARCH_SHARDS)).thenReturn(
unavailableShardsException()
);
when(securityIndex.getUnavailableReason(SecurityIndexManager.Availability.SEARCH_SHARDS)).thenReturn(unavailableShardsException());
doAnswer(invocation -> {
@SuppressWarnings("unchecked")
final var listener = (ActionListener<Void>) invocation.getArguments()[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,10 @@ public void testLicenseEnforcement() throws Exception {
// Disallow by license
when(licenseState.isAllowed(Security.ADVANCED_REMOTE_CLUSTER_SECURITY_FEATURE)).thenReturn(false);

final FakeRestRequest restRequest = new FakeRestRequest.Builder(NamedXContentRegistry.EMPTY).withContent(
new BytesArray("""
{
"metadata": {}
}"""),
XContentType.JSON
).withParams(Map.of("id", randomAlphaOfLength(10))).build();
final FakeRestRequest restRequest = new FakeRestRequest.Builder(NamedXContentRegistry.EMPTY).withContent(new BytesArray("""
{
"metadata": {}
}"""), XContentType.JSON).withParams(Map.of("id", randomAlphaOfLength(10))).build();
final SetOnce<RestResponse> responseSetOnce = new SetOnce<>();
final RestChannel restChannel = new AbstractRestChannel(restRequest, randomBoolean()) {
@Override
Expand Down

0 comments on commit c9fb15a

Please sign in to comment.