Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

import static java.util.Objects.requireNonNull;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatCode;
import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.mock;

import com.google.common.io.ByteStreams;
Expand Down Expand Up @@ -179,16 +179,15 @@ void setAndResetSpanExporter() {
try (AwsXrayRemoteSampler sampler = AwsXrayRemoteSampler.newBuilder(Resource.empty()).build()) {
// Setting span exporter should only work once
sampler.setSpanExporter(mock(SpanExporter.class));
assertThrows(
IllegalStateException.class, () -> sampler.setSpanExporter(mock(SpanExporter.class)));
assertThatThrownBy(() -> sampler.setSpanExporter(mock(SpanExporter.class)))
.isInstanceOf(IllegalStateException.class);
}
}

@Test
void adaptSamplingWithoutSpanExporter() {
assertThrows(
IllegalStateException.class,
() -> sampler.adaptSampling(mock(ReadableSpan.class), mock(SpanData.class)));
assertThatThrownBy(() -> sampler.adaptSampling(mock(ReadableSpan.class), mock(SpanData.class)))
.isInstanceOf(IllegalStateException.class);
}

@Test
Expand Down Expand Up @@ -224,7 +223,8 @@ void setAdaptiveSamplingConfig() {
AwsXrayAdaptiveSamplingConfig config =
AwsXrayAdaptiveSamplingConfig.builder().setVersion(1.0).build();
sampler.setAdaptiveSamplingConfig(config);
assertThrows(IllegalStateException.class, () -> sampler.setAdaptiveSamplingConfig(config));
assertThatThrownBy(() -> sampler.setAdaptiveSamplingConfig(config))
.isInstanceOf(IllegalStateException.class);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import static io.opentelemetry.semconv.HttpAttributes.HTTP_RESPONSE_STATUS_CODE;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -710,7 +710,8 @@ void setAdaptiveSamplingConfigTwice() {
AwsXrayAdaptiveSamplingConfig config =
AwsXrayAdaptiveSamplingConfig.builder().setVersion(1.0).build();
sampler.setAdaptiveSamplingConfig(config);
assertThrows(IllegalStateException.class, () -> sampler.setAdaptiveSamplingConfig(config));
assertThatThrownBy(() -> sampler.setAdaptiveSamplingConfig(config))
.isInstanceOf(IllegalStateException.class);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@

package io.opentelemetry.contrib.sampler.cel;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;

import dev.cel.common.CelAbstractSyntaxTree;
import dev.cel.common.CelValidationException;
Expand Down Expand Up @@ -35,7 +34,7 @@ void testToString() throws CelValidationException {
CelBasedSamplingExpression celExpression =
new CelBasedSamplingExpression(ast, Sampler.alwaysOn());
String expected = "CelBasedSamplingExpression{expression='1 == 1', delegate=AlwaysOnSampler}";
assertEquals(expected, celExpression.toString());
assertThat(celExpression.toString()).isEqualTo(expected);
}

@Test
Expand All @@ -45,28 +44,27 @@ void testEquals() throws CelValidationException {
CelCompilerFactory.standardCelCompilerBuilder().build().compile("1 == 1").getAst(),
Sampler.alwaysOn());

assertEquals(celExpressionOneEqualsOne1, celExpressionOneEqualsOne1);
assertNotEquals(celExpressionOneEqualsOne1, null);
assertThat(celExpressionOneEqualsOne1).isNotEqualTo(null);

CelBasedSamplingExpression celExpressionOneEqualsOne2 =
new CelBasedSamplingExpression(
CelCompilerFactory.standardCelCompilerBuilder().build().compile("1 == 1").getAst(),
Sampler.alwaysOn());

assertEquals(celExpressionOneEqualsOne1, celExpressionOneEqualsOne2);
assertThat(celExpressionOneEqualsOne1).isEqualTo(celExpressionOneEqualsOne2);

CelBasedSamplingExpression celExpressionTwoEqualsTwo =
new CelBasedSamplingExpression(
CelCompilerFactory.standardCelCompilerBuilder().build().compile("2 == 2").getAst(),
Sampler.alwaysOn());

assertNotEquals(celExpressionOneEqualsOne1, celExpressionTwoEqualsTwo);
assertThat(celExpressionOneEqualsOne1).isNotEqualTo(celExpressionTwoEqualsTwo);

CelBasedSamplingExpression celExpressionOneEqualsOneSamplerOff =
new CelBasedSamplingExpression(
CelCompilerFactory.standardCelCompilerBuilder().build().compile("1 == 1").getAst(),
Sampler.alwaysOff());
assertNotEquals(celExpressionOneEqualsOne1, celExpressionOneEqualsOneSamplerOff);
assertThat(celExpressionOneEqualsOne1).isNotEqualTo(celExpressionOneEqualsOneSamplerOff);
}

@Test
Expand All @@ -78,13 +76,13 @@ void testHashCode() throws CelValidationException {
int expectedHashCode1 = celExpression1.hashCode();
int expectedHashCode2 = celExpression1.hashCode();

assertEquals(expectedHashCode1, expectedHashCode2);
assertThat(expectedHashCode1).isEqualTo(expectedHashCode2);

CelBasedSamplingExpression celExpression2 =
new CelBasedSamplingExpression(
CelCompilerFactory.standardCelCompilerBuilder().build().compile("1 == 1").getAst(),
Sampler.alwaysOn());

assertEquals(expectedHashCode1, celExpression2.hashCode());
assertThat(expectedHashCode1).isEqualTo(celExpression2.hashCode());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
import static io.opentelemetry.contrib.disk.buffering.internal.storage.TestData.THIRD_LOG_RECORD;
import static io.opentelemetry.contrib.disk.buffering.internal.storage.TestData.getConfiguration;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.fail;
import static org.assertj.core.api.Assertions.fail;

import io.opentelemetry.contrib.disk.buffering.internal.serialization.deserializers.SignalDeserializer;
import io.opentelemetry.contrib.disk.buffering.internal.serialization.serializers.SignalSerializer;
Expand Down Expand Up @@ -65,15 +63,15 @@ void writeAndRead() throws IOException {
forwardToReadTime();

ReadableResult<LogRecordData> readResult = storage.readNext(DESERIALIZER);
assertNotNull(readResult);
assertThat(readResult).isNotNull();
assertThat(readResult.getContent()).containsExactly(FIRST_LOG_RECORD, SECOND_LOG_RECORD);
assertThat(destinationDir.list()).hasSize(1);

// Delete result and read again
readResult.delete();
readResult.close();
ReadableResult<LogRecordData> readResult2 = storage.readNext(DESERIALIZER);
assertNotNull(readResult2);
assertThat(readResult2).isNotNull();
assertThat(readResult2.getContent()).containsExactly(THIRD_LOG_RECORD);
assertThat(destinationDir.list()).hasSize(1);

Expand All @@ -88,7 +86,7 @@ void writeAndRead() throws IOException {

// Read again when no more data is available (delete file)
readResult2.close();
assertNull(storage.readNext(DESERIALIZER));
assertThat(storage.readNext(DESERIALIZER)).isNull();
assertThat(destinationDir.list()).isEmpty();
}

Expand All @@ -100,7 +98,7 @@ void interactionAfterClosed() throws IOException {
forwardToReadTime();

// Reading
assertNull(storage.readNext(DESERIALIZER));
assertThat(storage.readNext(DESERIALIZER)).isNull();

// Writing
assertThat(write(Collections.singletonList(THIRD_LOG_RECORD))).isFalse();
Expand All @@ -125,7 +123,7 @@ void whenTheReadTimeExpires_lookForNewFileToRead() throws IOException {

// Read
ReadableResult<LogRecordData> result = storage.readNext(DESERIALIZER);
assertNotNull(result);
assertThat(result).isNotNull();
assertThat(result.getContent()).containsExactly(THIRD_LOG_RECORD);
assertThat(destinationDir.list())
.containsExactlyInAnyOrder(
Expand Down Expand Up @@ -156,7 +154,7 @@ void whenNoMoreLinesToRead_lookForNewFileToRead() throws IOException {

// Read
ReadableResult<LogRecordData> result = storage.readNext(DESERIALIZER);
assertNotNull(result);
assertThat(result).isNotNull();
assertThat(result.getContent()).containsExactly(FIRST_LOG_RECORD, SECOND_LOG_RECORD);
assertThat(destinationDir.list())
.containsExactlyInAnyOrder(
Expand All @@ -166,7 +164,7 @@ void whenNoMoreLinesToRead_lookForNewFileToRead() throws IOException {

// Read again
ReadableResult<LogRecordData> result2 = storage.readNext(DESERIALIZER);
assertNotNull(result2);
assertThat(result2).isNotNull();
assertThat(result2.getContent()).containsExactly(THIRD_LOG_RECORD);
assertThat(destinationDir.list()).containsExactly(String.valueOf(secondFileWriteTime));
result2.close();
Expand All @@ -188,7 +186,7 @@ void deleteFilesWithCorruptedData() throws IOException {
currentTimeMillis.set(4000 + MIN_FILE_AGE_FOR_READ_MILLIS);

// Read
assertNull(storage.readNext(DESERIALIZER));
assertThat(storage.readNext(DESERIALIZER)).isNull();
assertThat(destinationDir.list()).containsExactly("4000"); // it tries 3 times max per call.
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import static io.opentelemetry.contrib.disk.buffering.internal.storage.TestData.getConfiguration;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.fail;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ public class ClientCallbackHandler implements CallbackHandler {
* @param password - authenticating password (plaintext)
* @param realm - authenticating realm
*/
public ClientCallbackHandler(final String username, final String password, final String realm) {
public ClientCallbackHandler(String username, String password, String realm) {
this.username = username;
this.password = password != null ? password.toCharArray() : null;
this.realm = realm;
}

@Override
public void handle(final Callback[] callbacks) throws UnsupportedCallbackException {
public void handle(Callback[] callbacks) throws UnsupportedCallbackException {
for (Callback callback : callbacks) {
if (callback instanceof NameCallback) {
((NameCallback) callback).setName(this.username);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
public class ConfigurationException extends RuntimeException {
private static final long serialVersionUID = 0L;

public ConfigurationException(final String message, final Throwable cause) {
public ConfigurationException(String message, Throwable cause) {
super(message, cause);
}

public ConfigurationException(final String message) {
public ConfigurationException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public GroovyMetricEnvironment(
*
* @param config - used to establish exporter type (logging by default) and connection info
*/
public GroovyMetricEnvironment(final JmxConfig config) {
public GroovyMetricEnvironment(JmxConfig config) {
this(
config,
"io.opentelemetry.contrib.jmxmetrics",
Expand All @@ -131,7 +131,7 @@ public void flush() {
meterProvider.forceFlush().join(10, TimeUnit.SECONDS);
}

protected static Attributes mapToAttributes(@Nullable final Map<String, String> labelMap) {
protected static Attributes mapToAttributes(@Nullable Map<String, String> labelMap) {
if (labelMap == null) {
return Attributes.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class GroovyRunner {
List<String> scriptSources = new ArrayList<>();
try {
if (config.targetSystems.size() != 0) {
for (final String target : config.targetSystems) {
for (String target : config.targetSystems) {
String systemResourcePath = "target-systems/" + target + ".groovy";
scriptSources.add(getTargetSystemResourceAsString(systemResourcePath));
}
Expand All @@ -59,7 +59,7 @@ public class GroovyRunner {

this.scripts = new ArrayList<>();
try {
for (final String source : scriptSources) {
for (String source : scriptSources) {
this.scripts.add(new GroovyShell().parse(source));
}
} catch (CompilationFailedException e) {
Expand All @@ -74,18 +74,18 @@ public class GroovyRunner {
new OtelHelper(jmxClient, this.groovyMetricEnvironment, config.aggregateAcrossMBeans);
binding.setVariable("otel", otelHelper);

for (final Script script : scripts) {
for (Script script : scripts) {
script.setBinding(binding);
}
}

private static String getFileAsString(final String fileName) throws IOException {
private static String getFileAsString(String fileName) throws IOException {
try (InputStream is = new FileInputStream(fileName)) {
return getFileFromInputStream(is);
}
}

private String getTargetSystemResourceAsString(final String targetSystem) throws IOException {
private String getTargetSystemResourceAsString(String targetSystem) throws IOException {
URL res = getClass().getClassLoader().getResource(targetSystem);
if (res == null) {
throw new ConfigurationException("Failed to load " + targetSystem);
Expand All @@ -98,15 +98,15 @@ private String getTargetSystemResourceAsString(final String targetSystem) throws
}

private static String getTargetSystemResourceFromJarAsString(URL res) throws IOException {
final String[] array = res.toString().split("!");
String[] array = res.toString().split("!");
if (array.length != 2) {
throw new ConfigurationException(
"Invalid path for target system resource from jar: " + res.toString());
}

final Map<String, String> env = Collections.emptyMap();
Map<String, String> env = Collections.emptyMap();
try {
try (final FileSystem fs = FileSystems.newFileSystem(URI.create(array[0]), env)) {
try (FileSystem fs = FileSystems.newFileSystem(URI.create(array[0]), env)) {
Path path = fs.getPath(array[1]);
try (InputStream is = Files.newInputStream(path)) {
return getFileFromInputStream(is);
Expand All @@ -117,7 +117,7 @@ private static String getTargetSystemResourceFromJarAsString(URL res) throws IOE
}
}

private static String getFileFromInputStream(final InputStream is) throws IOException {
private static String getFileFromInputStream(InputStream is) throws IOException {
if (is == null) {
return null;
}
Expand All @@ -134,7 +134,7 @@ private static String getFileFromInputStream(final InputStream is) throws IOExce
}

public void run() {
for (final Script script : scripts) {
for (Script script : scripts) {
script.run();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class JmxClient {
private final boolean registrySsl;
@Nullable private JMXConnector jmxConn;

JmxClient(final JmxConfig config) throws MalformedURLException {
JmxClient(JmxConfig config) throws MalformedURLException {
this.url = new JMXServiceURL(config.serviceUrl);
this.username = config.username;
this.password = config.password;
Expand Down Expand Up @@ -65,7 +65,7 @@ public MBeanServerConnection getConnection() {
env.put(
"jmx.remote.sasl.callback.handler",
new ClientCallbackHandler(this.username, this.password, this.realm));
} catch (final ReflectiveOperationException e) {
} catch (ReflectiveOperationException e) {
logger.warning("SASL unsupported in current environment: " + e.getMessage());
}

Expand All @@ -83,7 +83,7 @@ public MBeanServerConnection getConnection() {
* @param objectName ObjectName to query
* @return the sorted list of applicable ObjectName instances found by server
*/
public List<ObjectName> query(final ObjectName objectName) {
public List<ObjectName> query(ObjectName objectName) {
MBeanServerConnection mbsc = getConnection();
if (mbsc == null) {
return Collections.emptyList();
Expand Down
Loading