BewareMyPower commented on code in PR #23884:
URL: https://github.com/apache/pulsar/pull/23884#discussion_r1927334915
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/transaction/buffer/impl/TopicTransactionBuffer.java:
##########
@@ -129,6 +131,23 @@ public TopicTransactionBuffer(PersistentTopic topic) {
this.recover();
}
+ @VisibleForTesting
+ TopicTransactionBuffer(PersistentTopic topic, AbortedTxnProcessor
snapshotAbortedTxnProcessor,
+ AbortedTxnProcessor.SnapshotType snapshotType) {
+ super(State.None);
+ this.topic = topic;
+ this.timer =
topic.getBrokerService().getPulsar().getTransactionTimer();
+ this.takeSnapshotIntervalNumber = topic.getBrokerService().getPulsar()
+
.getConfiguration().getTransactionBufferSnapshotMaxTransactionCount();
+ this.takeSnapshotIntervalTime = topic.getBrokerService().getPulsar()
+
.getConfiguration().getTransactionBufferSnapshotMinTimeInMillis();
+ this.maxReadPosition =
topic.getManagedLedger().getLastConfirmedEntry();
+ this.snapshotAbortedTxnProcessor = snapshotAbortedTxnProcessor;
+ this.snapshotType = snapshotType;
+ this.maxReadPositionCallBack = topic.getMaxReadPositionCallBack();
+ this.recover();
+ }
Review Comment:
This new constructor overload has much duplicated code with the original
constructor. Please reuse the code. It only just reduces duplicated code, but
also simulate the real case more likely.
Here is a bad example. Assuming there is a `Demo` class whose constructor is:
```java
public Demo(Argument arg) {
this.field1 = arg.f();
this.field2 = arg.g();
}
```
If you wanted to pass a mocked `field2` and added a new constructor;
```java
Demo(Argument arg, Field2 field2) {
this.field1 = arg.h();
this.field2 = field2;
}
```
Then the new constructor will be meaningless. Because now `field` is not
`arg.f()` anymore.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]