Polish "Favor unchecked exceptions in APIs"

* Update copyrights
* Re-order PulsarException constructors
* Remove try/catch in DefaultPulsarProducerFactory.createProducer
This commit is contained in:
Chris Bono
2024-01-25 17:27:42 -06:00
parent 1126c468ca
commit dbec20fd61
16 changed files with 33 additions and 46 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2022-2023 the original author or authors.
* Copyright 2022-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,12 +30,12 @@ public class PulsarException extends NestedRuntimeException {
super(msg);
}
public PulsarException(String msg, Throwable cause) {
super(msg, cause);
}
public PulsarException(Throwable cause) {
this(cause.getMessage(), cause);
}
public PulsarException(String msg, Throwable cause) {
super(msg, cause);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2022-2023 the original author or authors.
* Copyright 2022-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -108,10 +108,10 @@ public class CachingPulsarProducerFactory<T> extends DefaultPulsarProducerFactor
private Producer<T> createCacheableProducer(Schema<T> schema, String topic,
@Nullable Collection<String> encryptionKeys, @Nullable List<ProducerBuilderCustomizer<T>> customizers) {
var producer = super.doCreateProducer(schema, topic, encryptionKeys, customizers);
return new ProducerWithCloseCallback<>(producer,
(p) -> this.logger.trace(() -> "Client closed producer %s but will skip actual closing"
.formatted(ProducerUtils.formatProducer(producer))));
var producer = super.doCreateProducer(schema, topic, encryptionKeys, customizers);
return new ProducerWithCloseCallback<>(producer,
(p) -> this.logger.trace(() -> "Client closed producer %s but will skip actual closing"
.formatted(ProducerUtils.formatProducer(producer))));
}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2022-2023 the original author or authors.
* Copyright 2022-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2022-2023 the original author or authors.
* Copyright 2022-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2022-2023 the original author or authors.
* Copyright 2022-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -110,30 +110,13 @@ public class DefaultPulsarProducerFactory<T> implements PulsarProducerFactory<T>
@Override
public Producer<T> createProducer(Schema<T> schema, @Nullable String topic,
@Nullable ProducerBuilderCustomizer<T> customizer) {
try {
return doCreateProducer(schema, topic, null,
customizer != null ? Collections.singletonList(customizer) : null);
}
catch (PulsarException ex) {
throw ex;
}
catch (Exception ex) {
throw new PulsarException(PulsarClientException.unwrap(ex));
}
return doCreateProducer(schema, topic, null, customizer != null ? Collections.singletonList(customizer) : null);
}
@Override
public Producer<T> createProducer(Schema<T> schema, @Nullable String topic,
@Nullable Collection<String> encryptionKeys, @Nullable List<ProducerBuilderCustomizer<T>> customizers) {
try {
return doCreateProducer(schema, topic, encryptionKeys, customizers);
}
catch (PulsarException ex) {
throw ex;
}
catch (Exception ex) {
throw new PulsarException(PulsarClientException.unwrap(ex));
}
return doCreateProducer(schema, topic, encryptionKeys, customizers);
}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2023-2023 the original author or authors.
* Copyright 2023-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2022-2023 the original author or authors.
* Copyright 2022-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2022-2023 the original author or authors.
* Copyright 2022-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2022-2023 the original author or authors.
* Copyright 2022-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2022-2023 the original author or authors.
* Copyright 2022-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2022-2023 the original author or authors.
* Copyright 2022-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2022-2023 the original author or authors.
* Copyright 2022-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2023-2023 the original author or authors.
* Copyright 2023-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -38,6 +38,7 @@ import org.junit.jupiter.api.Test;
import org.mockito.InOrder;
import org.springframework.lang.Nullable;
import org.springframework.pulsar.PulsarException;
import org.springframework.pulsar.test.support.PulsarTestContainerSupport;
/**
@@ -86,7 +87,8 @@ class DefaultPulsarConsumerFactoryTests implements PulsarTestContainerSupport {
@Test
void withSchemaOnly() {
assertThatThrownBy(() -> consumerFactory.createConsumer(SCHEMA, null, null, null, null))
.isInstanceOf(InvalidConfigurationException.class)
.isInstanceOf(PulsarException.class)
.hasCauseInstanceOf(InvalidConfigurationException.class)
.hasMessageContaining("Topic name must be set on the consumer builder");
}
@@ -95,7 +97,8 @@ class DefaultPulsarConsumerFactoryTests implements PulsarTestContainerSupport {
void withSchemaAndTopics() {
assertThatThrownBy(
() -> consumerFactory.createConsumer(SCHEMA, Collections.singletonList("topic0"), null, null, null))
.isInstanceOf(InvalidConfigurationException.class)
.isInstanceOf(PulsarException.class)
.hasCauseInstanceOf(InvalidConfigurationException.class)
.hasMessageContaining("Subscription name must be set on the consumer builder");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2022-2023 the original author or authors.
* Copyright 2022-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2023 the original author or authors.
* Copyright 2023-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -154,8 +154,9 @@ public class PulsarReaderStartMessageIdTests extends PulsarReaderTestsBase {
for (int i = 0; i < 10; i++) {
messageIds[i] = pulsarTemplate.send("with-customizer-reader-topic", "hello john doe-");
}
cb.startMessageId(messageIds[4]); // the first message read is the one
// after this message id.
// the first message read is the one after this message id
cb.startMessageId(messageIds[4]);
};
}