Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Producer getting producer busy is removing existing producer from list #11804

Merged
merged 2 commits into from Aug 27, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -147,7 +147,10 @@ public int hashCode() {
public boolean equals(Object obj) {
if (obj instanceof Producer) {
Producer other = (Producer) obj;
return Objects.equals(producerName, other.producerName) && Objects.equals(topic, other.topic);
return Objects.equals(producerName, other.producerName)
&& Objects.equals(topic, other.topic)
&& producerId == other.producerId
&& Objects.equals(cnx, other.cnx);
}

return false;
Expand Down
Expand Up @@ -41,6 +41,7 @@
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -1544,6 +1545,23 @@ protected void handleSeek(CommandSeek seek) {
}
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ServerCnx other = (ServerCnx) o;
return Objects.equals(ctx().channel().id(), other.ctx().channel().id());
}

@Override
public int hashCode() {
return Objects.hash(ctx().channel().id());
}

@Override
protected void handleCloseProducer(CommandCloseProducer closeProducer) {
checkArgument(state == State.Connected);
Expand Down
Expand Up @@ -1814,4 +1814,49 @@ public void testWithEventTime() throws Exception {
assertEquals(msg.getValue(), "test");
assertEquals(msg.getEventTime(), 5);
}

@Test
public void testProducerBusy() throws Exception {
final String topicName = "prop/ns-abc/producer-busy-" + System.nanoTime();

@Cleanup
Producer<String> producer = pulsarClient.newProducer(Schema.STRING)
.topic(topicName)
.producerName("xxx")
.create();

assertEquals(admin.topics().getStats(topicName).getPublishers().size(), 1);

for (int i =0; i < 5; i++) {
try {
pulsarClient.newProducer(Schema.STRING)
.topic(topicName)
.producerName("xxx")
.create();
fail("Should have failed");
} catch (ProducerBusyException e) {
// Expected
}

assertEquals(admin.topics().getStats(topicName).getPublishers().size(), 1);
}

// Try from different connection
@Cleanup
PulsarClient client2 = PulsarClient.builder()
.serviceUrl(getPulsar().getBrokerServiceUrl())
.build();

try {
client2.newProducer(Schema.STRING)
.topic(topicName)
.producerName("xxx")
.create();
fail("Should have failed");
} catch (ProducerBusyException e) {
// Expected
}

assertEquals(admin.topics().getStats(topicName).getPublishers().size(), 1);
}
}