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 @@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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);
}
}