Skip to content

Commit

Permalink
Factor out a module for annotations (kroxylicious#1018)
Browse files Browse the repository at this point in the history
* Factor out a module for annotations
* Apply some @VisibleForTesting

Signed-off-by: Tom Bentley <[email protected]>
  • Loading branch information
tombentley authored Feb 20, 2024
1 parent 7e4a3d5 commit 4f21750
Show file tree
Hide file tree
Showing 20 changed files with 89 additions and 15 deletions.
22 changes: 22 additions & 0 deletions kroxylicious-annotations/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright Kroxylicious Authors.
Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
-->
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.kroxylicious</groupId>
<artifactId>kroxylicious-parent</artifactId>
<version>0.5.0-SNAPSHOT</version>
</parent>

<artifactId>kroxylicious-annotations</artifactId>
<description></description>

</project>
4 changes: 4 additions & 0 deletions kroxylicious-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
<artifactId>kroxylicious-api</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.kroxylicious</groupId>
<artifactId>kroxylicious-annotations</artifactId>
</dependency>

<!-- project dependencies - test -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import org.slf4j.LoggerFactory;
import org.slf4j.event.Level;

import io.kroxylicious.proxy.tag.VisibleForTesting;

public class BannerLogger {

public static final String DEFAULT_BANNER_LOCATION = "banner.txt";
Expand All @@ -44,7 +46,8 @@ public void log() {
bannerReader.get().forEach(line -> targetLogger.atLevel(targetLevel).log(line));
}

/* test */ static class BannerSupplier implements Supplier<Stream<String>> {
@VisibleForTesting
static class BannerSupplier implements Supplier<Stream<String>> {

private final Supplier<Stream<String>> linesSupplier;
private final Set<String> licenseLines;
Expand All @@ -64,7 +67,8 @@ public Stream<String> get() {
}
}

/* test */ static class FileLinesSupplier implements Supplier<Stream<String>> {
@VisibleForTesting
static class FileLinesSupplier implements Supplier<Stream<String>> {

private final String resourceName;

Expand Down
6 changes: 6 additions & 0 deletions kroxylicious-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@
<dependencyManagement>
<dependencies>
<!-- Core Production dependencies -->
<dependency>
<groupId>io.kroxylicious</groupId>
<artifactId>kroxylicious-annotations</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>io.kroxylicious</groupId>
<artifactId>kroxylicious-api</artifactId>
Expand Down
4 changes: 4 additions & 0 deletions kroxylicious-filters/kroxylicious-encryption/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
<groupId>io.kroxylicious</groupId>
<artifactId>kroxylicious-api</artifactId>
</dependency>
<dependency>
<groupId>io.kroxylicious</groupId>
<artifactId>kroxylicious-annotations</artifactId>
</dependency>

<dependency>
<groupId>io.kroxylicious</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public final class Dek<E> {
* <tr><td colspan="3">«{@link #END}» // key gets destroyed </td> </tr>
* </table>
*/
final AtomicLong outstandingCryptors;
private final AtomicLong outstandingCryptors;

private static final long START = combine(1, 1);
private static final long END = combine(-1, -1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import javax.annotation.concurrent.NotThreadSafe;
import javax.security.auth.Destroyable;

import io.kroxylicious.proxy.tag.VisibleForTesting;

import edu.umd.cs.findbugs.annotations.NonNull;

/**
Expand Down Expand Up @@ -40,6 +42,7 @@ class Wrapping96BitCounter implements Destroyable {
hi = rng.nextInt();
}

@VisibleForTesting
int sizeBytes() {
return 12;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import io.kroxylicious.filter.encryption.dek.ExhaustedDekException;
import io.kroxylicious.filter.encryption.records.RecordStream;
import io.kroxylicious.kms.service.Serde;
import io.kroxylicious.proxy.tag.VisibleForTesting;

import edu.umd.cs.findbugs.annotations.NonNull;

Expand Down Expand Up @@ -95,7 +96,7 @@ public InBandEncryptionManager(@NonNull Serde<E> edekSerde,

}

// @VisibleForTesting
@VisibleForTesting
CompletionStage<Dek<E>> currentDek(@NonNull EncryptionScheme<K> encryptionScheme) {
// todo should we add some scheduled timeout as well? or should we rely on the KMS to timeout appropriately.
return dekCache.get(encryptionScheme, filterThreadExecutor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.kroxylicious.filter.encryption.EncryptionException;
import io.kroxylicious.filter.encryption.ParcelVersion;
import io.kroxylicious.filter.encryption.RecordField;
import io.kroxylicious.proxy.tag.VisibleForTesting;

import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
Expand All @@ -32,6 +33,7 @@ public class Parcel {
private static final Header[] ABSENT_HEADERS = new Header[0];
private static final ByteBuffer ABSENT_VALUE = ByteBuffer.allocate(0);

@VisibleForTesting
static int sizeOfParcel(ParcelVersion parcelVersion, Set<RecordField> recordFields, Record kafkaRecord) {
switch (parcelVersion) {
case V1:
Expand Down
1 change: 1 addition & 0 deletions kroxylicious-filters/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<exclude>io.kroxylicious</exclude>
</excludes>
<includes>
<include>io.kroxylicious:kroxylicious-annotations</include>
<include>io.kroxylicious:kroxylicious-api</include>
<include>io.kroxylicious:kroxylicious-filter-test-support</include>
<include>io.kroxylicious:kroxylicious-kms</include>
Expand Down
4 changes: 4 additions & 0 deletions kroxylicious-kms-provider-hashicorp-vault/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
<groupId>io.kroxylicious</groupId>
<artifactId>kroxylicious-kms</artifactId>
</dependency>
<dependency>
<groupId>io.kroxylicious</groupId>
<artifactId>kroxylicious-annotations</artifactId>
</dependency>
<dependency>
<groupId>io.kroxylicious</groupId>
<artifactId>kroxylicious-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import io.kroxylicious.kms.service.Serde;
import io.kroxylicious.kms.service.UnknownAliasException;
import io.kroxylicious.kms.service.UnknownKeyException;
import io.kroxylicious.proxy.tag.VisibleForTesting;

import edu.umd.cs.findbugs.annotations.NonNull;

Expand Down Expand Up @@ -80,7 +81,8 @@ private URI ensureEndsInSlash(URI uri) {
return uri.resolve(uri.getPath() + "/").normalize();
}

/* exposed for testing */ HttpClient createClient(SSLContext sslContext) {
@VisibleForTesting
HttpClient createClient(SSLContext sslContext) {
HttpClient.Builder builder = HttpClient.newBuilder();
if (sslContext != null) {
builder.sslContext(sslContext);
Expand Down Expand Up @@ -179,7 +181,8 @@ public Serde<VaultEdek> edekSerde() {
return new VaultEdekSerde();
}

/* exposed for testing */ HttpRequest.Builder createVaultRequest() {
@VisibleForTesting
HttpRequest.Builder createVaultRequest() {
return HttpRequest.newBuilder()
.timeout(timeout)
.header("X-Vault-Token", vaultToken)
Expand All @@ -198,7 +201,8 @@ else if (r.statusCode() != 200) {
};
}

/* testing */ URI getVaultTransitEngineUri() {
@VisibleForTesting
URI getVaultTransitEngineUri() {
return vaultTransitEngineUrl;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import io.kroxylicious.proxy.config.tls.TrustProvider;
import io.kroxylicious.proxy.config.tls.TrustProviderVisitor;
import io.kroxylicious.proxy.config.tls.TrustStore;
import io.kroxylicious.proxy.tag.VisibleForTesting;

import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
Expand Down Expand Up @@ -97,7 +98,7 @@ public SSLContext sslContext() {
}
}

/* exposed for testing */
@VisibleForTesting
static KeyManager[] getKeyManagers(KeyProvider key) {
return key.accept(new KeyProviderVisitor<>() {
@Override
Expand Down Expand Up @@ -149,7 +150,7 @@ private static SSLContext getSslContext(TrustManager[] trustManagers, KeyManager
}
}

/* exposed for testing */
@VisibleForTesting
static TrustManager[] getTrustManagers(TrustProvider trust) {

return trust.accept(new TrustProviderVisitor<>() {
Expand Down
4 changes: 4 additions & 0 deletions kroxylicious-runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@

<dependencies>
<!-- project dependencies - runtime and compile -->
<dependency>
<groupId>io.kroxylicious</groupId>
<artifactId>kroxylicious-annotations</artifactId>
</dependency>
<dependency>
<groupId>io.kroxylicious</groupId>
<artifactId>kroxylicious-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.kroxylicious.proxy.micrometer.MicrometerConfigurationHook;
import io.kroxylicious.proxy.micrometer.MicrometerConfigurationHookContributor;
import io.kroxylicious.proxy.service.ContributionManager;
import io.kroxylicious.proxy.tag.VisibleForTesting;

import static io.kroxylicious.proxy.service.Context.wrap;

Expand Down Expand Up @@ -59,7 +60,7 @@ private List<MicrometerConfigurationHook> registerHooks(List<MicrometerDefinitio
*
* @param registry registry
*/
/* test */
@VisibleForTesting
static void preventDifferentTagNameRegistration(CompositeMeterRegistry registry) {
registry.config().meterFilter(new MeterFilter() {
@Override
Expand Down Expand Up @@ -96,4 +97,4 @@ public void close() {
copy.forEach(Metrics.globalRegistry::remove);
Metrics.removeRegistry(prometheusMeterRegistry);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import io.kroxylicious.proxy.model.VirtualCluster;
import io.kroxylicious.proxy.service.HostPort;
import io.kroxylicious.proxy.tag.VisibleForTesting;

/**
* The endpoint registry is responsible for associating network endpoints with broker/bootstrap addresses of virtual clusters.
Expand Down Expand Up @@ -421,11 +422,13 @@ private Set<VirtualClusterBrokerBinding> constructPossibleBindingsToCreate(Virtu
return creations;
}

/* test */ boolean isRegistered(VirtualCluster virtualCluster) {
@VisibleForTesting
boolean isRegistered(VirtualCluster virtualCluster) {
return registeredVirtualClusters.containsKey(virtualCluster);
}

/* test */ int listeningChannelCount() {
@VisibleForTesting
int listeningChannelCount() {
return listeningChannels.size();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import io.micrometer.core.instrument.binder.system.ProcessorMetrics;
import io.micrometer.core.instrument.binder.system.UptimeMetrics;

import io.kroxylicious.proxy.tag.VisibleForTesting;

public class StandardBindersHook implements MicrometerConfigurationHook {
private static final Logger log = LoggerFactory.getLogger(StandardBindersHook.class);
private final StandardBindersHookConfig config;
Expand Down Expand Up @@ -72,7 +74,8 @@ public void close() {
});
}

/* testing */ protected MeterBinder getBinder(String binderName) {
@VisibleForTesting
protected MeterBinder getBinder(String binderName) {
return switch (binderName) {
case "UptimeMetrics" -> new UptimeMetrics();
case "ProcessorMetrics" -> new ProcessorMetrics();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;

import io.kroxylicious.proxy.tag.VisibleForTesting;

/**
* @deprecated We want to remove the generic Contributor type so this has to be rethought/reimplemented.
*/
Expand All @@ -26,7 +28,8 @@ private ContributionManager() {
this(ServiceLoader::load);
}

/* test */ ContributionManager(Function<Class, Iterable> loaderFunction) {
@VisibleForTesting
ContributionManager(Function<Class, Iterable> loaderFunction) {
this.contributors = new ConcurrentHashMap<>();
this.loaderFunction = loaderFunction;
}
Expand Down
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@
</dependencyManagement>

<modules>
<module>kroxylicious-annotations</module>
<module>kroxylicious-kms</module>
<module>kroxylicious-kms-test-support</module>
<module>kroxylicious-kms-provider-kroxylicious-inmemory</module>
Expand Down Expand Up @@ -765,6 +766,9 @@
<ignoredUnusedDeclaredDependency>org.apache.logging.log4j:log4j-slf4j2-impl</ignoredUnusedDeclaredDependency>
<!-- for some reason, the analyzer fails to detect netty-transport-native-unix-common use -->
<ignoredUnusedDeclaredDependency>io.netty:netty-transport-native-unix-common</ignoredUnusedDeclaredDependency>
<!-- dependency analyzer seems not to grok that a dependency on a
@Retention(RetentionPolicy.SOURCE) annotation is still a dependency -->
<ignoredUnusedDeclaredDependency>io.kroxylicious:kroxylicious-annotations</ignoredUnusedDeclaredDependency>
</ignoredUnusedDeclaredDependencies>
<ignoredDependencies>
<!-- Kroxylicious junit extension requires this to be on the classpath -->
Expand Down

0 comments on commit 4f21750

Please sign in to comment.