Skip to content

Commit 501c502

Browse files
authored
Replace the SDK test JAR with a flume-ng-sdk-test module (#495)
The site build runs `mvnw -Dmaven.test.skip install`, which also skips `jar:test-jar`. Maven still resolves the full test classpath before `compiler:testCompile` and `surefire:test` can read their skip flags, so the cross-module `flume-ng-sdk:tests` dependency was demanded but never produced and `deploy-site` failed to resolve it. Assisted-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WnSh7gt5XaRzNgDYLuFzZ6
1 parent c0d73dc commit 501c502

20 files changed

Lines changed: 255 additions & 59 deletions

File tree

flume-bom/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@
103103
<artifactId>flume-ng-sdk</artifactId>
104104
<version>${project.version}</version>
105105
</dependency>
106+
<dependency>
107+
<groupId>org.apache.flume</groupId>
108+
<artifactId>flume-ng-sdk-test</artifactId>
109+
<version>${project.version}</version>
110+
</dependency>
106111
<dependency>
107112
<groupId>org.apache.flume</groupId>
108113
<artifactId>flume-ng-node</artifactId>

flume-ng-core/pom.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@
4646

4747
<dependency>
4848
<groupId>org.apache.flume</groupId>
49-
<artifactId>flume-ng-sdk</artifactId>
50-
<classifier>tests</classifier>
49+
<artifactId>flume-ng-sdk-test</artifactId>
5150
<scope>test</scope>
5251
</dependency>
5352

flume-ng-core/src/test/java/org/apache/flume/sink/TestRollingFileSink.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import org.apache.flume.event.SimpleEvent;
3333
import org.apache.flume.exception.ChannelException;
3434
import org.apache.flume.instrumentation.SinkCounter;
35-
import org.apache.flume.util.Whitebox;
35+
import org.apache.flume.sdk.test.Whitebox;
3636
import org.apache.logging.log4j.LogManager;
3737
import org.apache.logging.log4j.Logger;
3838
import org.junit.After;

flume-ng-sdk-test/pom.xml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Licensed to the Apache Software Foundation (ASF) under one or more
4+
~ contributor license agreements. See the NOTICE file distributed with
5+
~ this work for additional information regarding copyright ownership.
6+
~ The ASF licenses this file to you under the Apache License, Version 2.0
7+
~ (the "License"); you may not use this file except in compliance with
8+
~ the License. You may obtain a copy of the License at
9+
~
10+
~ http://www.apache.org/licenses/LICENSE-2.0
11+
~
12+
~ Unless required by applicable law or agreed to in writing, software
13+
~ distributed under the License is distributed on an "AS IS" BASIS,
14+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
~ See the License for the specific language governing permissions and
16+
~ limitations under the License.
17+
-->
18+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
19+
<modelVersion>4.0.0</modelVersion>
20+
21+
<parent>
22+
<groupId>org.apache.flume</groupId>
23+
<artifactId>flume-parent</artifactId>
24+
<version>${revision}</version>
25+
<relativePath>../flume-parent/pom.xml</relativePath>
26+
</parent>
27+
28+
<artifactId>flume-ng-sdk-test</artifactId>
29+
<name>Flume NG SDK Test</name>
30+
<description>Test fixtures shared by the Flume modules.
31+
The fixtures live in `main`, so that they are packaged in a regular JAR instead of a test JAR.</description>
32+
33+
<properties>
34+
<!-- This artifact was never released before -->
35+
<bnd.baseline.fail.on.missing>false</bnd.baseline.fail.on.missing>
36+
<!-- `TestKeyStores.certificate()` hands out the `X509Certificate` it was built from, which SpotBugs
37+
reports as exposing internal representation. -->
38+
<spotbugs.maxAllowedViolations>1</spotbugs.maxAllowedViolations>
39+
<module.name>org.apache.flume.sdk.test</module.name>
40+
</properties>
41+
42+
<dependencies>
43+
44+
<dependency>
45+
<groupId>org.apache.commons</groupId>
46+
<artifactId>commons-lang3</artifactId>
47+
</dependency>
48+
49+
<dependency>
50+
<groupId>org.bouncycastle</groupId>
51+
<artifactId>bcpkix-jdk18on</artifactId>
52+
</dependency>
53+
54+
<dependency>
55+
<groupId>org.bouncycastle</groupId>
56+
<artifactId>bcprov-jdk18on</artifactId>
57+
</dependency>
58+
59+
<dependency>
60+
<groupId>junit</groupId>
61+
<artifactId>junit</artifactId>
62+
<scope>test</scope>
63+
</dependency>
64+
65+
</dependencies>
66+
</project>

flume-ng-sdk/src/test/java/org/apache/flume/util/TestKeyStores.java renamed to flume-ng-sdk-test/src/main/java/org/apache/flume/sdk/test/TestKeyStores.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
package org.apache.flume.util;
17+
package org.apache.flume.sdk.test;
1818

1919
import java.io.OutputStream;
2020
import java.nio.file.Files;

flume-ng-sdk/src/test/java/org/apache/flume/util/Whitebox.java renamed to flume-ng-sdk-test/src/main/java/org/apache/flume/sdk/test/Whitebox.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
package org.apache.flume.util;
17+
package org.apache.flume.sdk.test;
1818

1919
import org.apache.commons.lang3.reflect.FieldUtils;
2020

flume-ng-sdk/src/test/java/org/apache/flume/util/X509Certificates.java renamed to flume-ng-sdk-test/src/main/java/org/apache/flume/sdk/test/X509Certificates.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
package org.apache.flume.util;
17+
package org.apache.flume.sdk.test;
1818

1919
import java.math.BigInteger;
2020
import java.security.KeyPair;
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to you under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.flume.sdk.test;
18+
19+
import java.io.InputStream;
20+
import java.nio.file.Files;
21+
import java.nio.file.Path;
22+
import java.security.KeyStore;
23+
import java.security.cert.X509Certificate;
24+
import org.junit.Assert;
25+
import org.junit.Test;
26+
27+
public class TestSelfSignedKeyStores {
28+
29+
private static final String PASSWORD = "password";
30+
31+
@Test
32+
public void testKeyStoreHoldsThePrivateKey() throws Exception {
33+
TestKeyStores credentials = TestKeyStores.selfSigned("CN=localhost");
34+
KeyStore keyStore = credentials.keyStore("JKS", PASSWORD);
35+
36+
Assert.assertTrue(keyStore.isKeyEntry("key"));
37+
Assert.assertEquals(credentials.certificate(), keyStore.getCertificateChain("key")[0]);
38+
Assert.assertNotNull(keyStore.getKey("key", PASSWORD.toCharArray()));
39+
}
40+
41+
@Test
42+
public void testTrustStoreHoldsOnlyTheCertificate() throws Exception {
43+
TestKeyStores credentials = TestKeyStores.selfSigned("CN=localhost");
44+
KeyStore trustStore = credentials.trustStore("JKS");
45+
46+
Assert.assertFalse(trustStore.isKeyEntry("cert"));
47+
Assert.assertEquals(credentials.certificate(), trustStore.getCertificate("cert"));
48+
}
49+
50+
@Test
51+
public void testWrittenKeyStoreCanBeReloaded() throws Exception {
52+
TestKeyStores credentials = TestKeyStores.selfSigned("CN=localhost");
53+
Path file = Files.createTempFile("keystore", ".jks");
54+
try {
55+
credentials.writeKeyStore(file, "JKS", PASSWORD);
56+
57+
KeyStore reloaded = KeyStore.getInstance("JKS");
58+
try (InputStream in = Files.newInputStream(file)) {
59+
reloaded.load(in, PASSWORD.toCharArray());
60+
}
61+
X509Certificate certificate = (X509Certificate) reloaded.getCertificateChain("key")[0];
62+
Assert.assertEquals(credentials.certificate(), certificate);
63+
} finally {
64+
Files.deleteIfExists(file);
65+
}
66+
}
67+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to you under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.flume.sdk.test;
18+
19+
import org.junit.Assert;
20+
import org.junit.Test;
21+
22+
public class TestWhitebox {
23+
24+
private static final class Target {
25+
private String value = "initial";
26+
}
27+
28+
@Test
29+
public void testGetInternalState() {
30+
Assert.assertEquals("initial", Whitebox.getInternalState(new Target(), "value"));
31+
}
32+
33+
@Test
34+
public void testSetInternalState() {
35+
Target target = new Target();
36+
Whitebox.setInternalState(target, "value", "replaced");
37+
Assert.assertEquals("replaced", target.value);
38+
}
39+
40+
@Test(expected = RuntimeException.class)
41+
public void testUnknownFieldFails() {
42+
Whitebox.getInternalState(new Target(), "missing");
43+
}
44+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to you under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.flume.sdk.test;
18+
19+
import java.security.KeyPair;
20+
import java.security.cert.X509Certificate;
21+
import java.util.Collections;
22+
import java.util.Date;
23+
import org.junit.Assert;
24+
import org.junit.Test;
25+
26+
public class TestX509Certificates {
27+
28+
@Test
29+
public void testSelfSignedCertificate() throws Exception {
30+
KeyPair keyPair = X509Certificates.generateKeyPair();
31+
X509Certificate certificate = X509Certificates.generateSelfSignedCertificate(keyPair, "CN=localhost");
32+
33+
Assert.assertEquals(
34+
"CN=localhost", certificate.getSubjectX500Principal().getName());
35+
Assert.assertEquals(certificate.getSubjectX500Principal(), certificate.getIssuerX500Principal());
36+
// A self-signed certificate verifies against its own public key.
37+
certificate.verify(keyPair.getPublic());
38+
certificate.checkValidity(new Date());
39+
}
40+
41+
@Test
42+
public void testServerCertificateExtensions() throws Exception {
43+
KeyPair keyPair = X509Certificates.generateKeyPair();
44+
X509Certificate certificate = X509Certificates.generateSelfSignedCertificate(keyPair, "CN=localhost");
45+
46+
// A negative path length constraint marks a certificate that is not a CA.
47+
Assert.assertEquals(-1, certificate.getBasicConstraints());
48+
Assert.assertEquals(Collections.singletonList("1.3.6.1.5.5.7.3.1"), certificate.getExtendedKeyUsage());
49+
}
50+
51+
@Test
52+
public void testKeyPairsAreDistinct() {
53+
Assert.assertNotEquals(
54+
X509Certificates.generateKeyPair().getPrivate(),
55+
X509Certificates.generateKeyPair().getPrivate());
56+
}
57+
}

0 commit comments

Comments
 (0)