-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Add getTxnID method in Transaction.java #11438
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f6ecfd7
Add getTxnID method in Transaction.java
liangyepianzhou f5c5499
Modify the Awaitility.await() in TransactionTest and doc in Transaction
liangyepianzhou 8fd8e65
Optimize waitForCoordinatorToBeAvailable method in TransactionTest
liangyepianzhou 1b377cd
Fixed the details in TransactionTest
liangyepianzhou ee4daff
Fixed the problem of naming in TransactionTest
liangyepianzhou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,8 @@ | |
package org.apache.pulsar.broker.transaction; | ||
|
||
import static org.apache.pulsar.transaction.coordinator.impl.MLTransactionLogImpl.TRANSACTION_LOG_PREFIX; | ||
import static org.testng.AssertJUnit.assertEquals; | ||
import static org.testng.AssertJUnit.assertNotNull; | ||
import com.google.common.collect.Sets; | ||
import java.util.Optional; | ||
import java.util.concurrent.CompletableFuture; | ||
|
@@ -32,12 +34,18 @@ | |
import org.apache.pulsar.client.api.PulsarClient; | ||
import org.apache.pulsar.client.api.PulsarClientException; | ||
import org.apache.pulsar.client.api.SubscriptionType; | ||
import org.apache.pulsar.client.api.transaction.Transaction; | ||
import org.apache.pulsar.client.api.transaction.TxnID; | ||
import org.apache.pulsar.common.naming.NamespaceName; | ||
import org.apache.pulsar.common.naming.TopicDomain; | ||
import org.apache.pulsar.common.naming.TopicName; | ||
import org.apache.pulsar.common.policies.data.ClusterData; | ||
import org.apache.pulsar.common.policies.data.TenantInfoImpl; | ||
import org.apache.pulsar.common.util.collections.ConcurrentOpenHashMap; | ||
import org.apache.pulsar.transaction.coordinator.TransactionCoordinatorID; | ||
import org.apache.pulsar.transaction.coordinator.TransactionMetadataStore; | ||
import org.apache.pulsar.transaction.coordinator.TransactionMetadataStoreState; | ||
import org.apache.pulsar.transaction.coordinator.impl.MLTransactionMetadataStore; | ||
import org.awaitility.Awaitility; | ||
import org.testng.Assert; | ||
import org.testng.annotations.AfterMethod; | ||
|
@@ -53,23 +61,26 @@ public class TransactionTest extends TransactionTestBase { | |
|
||
private static final String TENANT = "tnx"; | ||
private static final String NAMESPACE1 = TENANT + "/ns1"; | ||
private static final int NUM_BROKERS = 1; | ||
private static final int NUM_PARTITIONS = 1; | ||
|
||
@BeforeMethod | ||
protected void setup() throws Exception { | ||
this.setBrokerCount(1); | ||
this.setBrokerCount(NUM_BROKERS); | ||
this.internalSetup(); | ||
|
||
String[] brokerServiceUrlArr = getPulsarServiceList().get(0).getBrokerServiceUrl().split(":"); | ||
String webServicePort = brokerServiceUrlArr[brokerServiceUrlArr.length - 1]; | ||
admin.clusters().createCluster(CLUSTER_NAME, ClusterData.builder().serviceUrl("http://localhost:" + webServicePort).build()); | ||
admin.clusters().createCluster(CLUSTER_NAME, ClusterData.builder() | ||
.serviceUrl("http://localhost:" + webServicePort).build()); | ||
admin.tenants().createTenant(TENANT, | ||
new TenantInfoImpl(Sets.newHashSet("appid1"), Sets.newHashSet(CLUSTER_NAME))); | ||
admin.namespaces().createNamespace(NAMESPACE1); | ||
|
||
admin.tenants().createTenant(NamespaceName.SYSTEM_NAMESPACE.getTenant(), | ||
new TenantInfoImpl(Sets.newHashSet("appid1"), Sets.newHashSet(CLUSTER_NAME))); | ||
admin.namespaces().createNamespace(NamespaceName.SYSTEM_NAMESPACE.toString()); | ||
admin.topics().createPartitionedTopic(TopicName.TRANSACTION_COORDINATOR_ASSIGN.toString(), 1); | ||
admin.topics().createPartitionedTopic(TopicName.TRANSACTION_COORDINATOR_ASSIGN.toString(), NUM_PARTITIONS); | ||
pulsarClient.close(); | ||
pulsarClient = PulsarClient.builder() | ||
.serviceUrl(getPulsarServiceList().get(0).getBrokerServiceUrl()) | ||
|
@@ -139,4 +150,21 @@ public Consumer<byte[]> getConsumer(String topicName, String subName) throws Pul | |
.enableBatchIndexAcknowledgment(true) | ||
.subscribe(); | ||
} | ||
|
||
@Test | ||
public void testGetTxnID() throws Exception { | ||
// wait tc init success to ready state | ||
Assert.assertTrue(waitForCoordinatorToBeAvailable(NUM_BROKERS, NUM_PARTITIONS)); | ||
Transaction transaction = pulsarClient.newTransaction() | ||
.build().get(); | ||
TxnID txnID = transaction.getTxnID(); | ||
Assert.assertEquals(txnID.getLeastSigBits(), 0); | ||
Assert.assertEquals(txnID.getMostSigBits(), 0); | ||
transaction.abort(); | ||
transaction = pulsarClient.newTransaction() | ||
.build().get(); | ||
txnID = transaction.getTxnID(); | ||
Assert.assertEquals(txnID.getLeastSigBits(), 1); | ||
Assert.assertEquals(txnID.getMostSigBits(), 0); | ||
Comment on lines
+167
to
+168
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We will always get transaction ID (1,0) here? I mean we can just check the txnID is not null. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In fact it should always be this |
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why need to create the transaction again?