20
20
import org .apache .kafka .clients .admin .Admin ;
21
21
import org .apache .kafka .clients .admin .AdminClientConfig ;
22
22
import org .apache .kafka .clients .admin .FenceProducersOptions ;
23
- import org .apache .kafka .clients .producer .KafkaProducer ;
23
+ import org .apache .kafka .clients .producer .Producer ;
24
24
import org .apache .kafka .clients .producer .ProducerConfig ;
25
25
import org .apache .kafka .clients .producer .ProducerRecord ;
26
26
import org .apache .kafka .common .errors .ApiException ;
27
27
import org .apache .kafka .common .errors .InvalidProducerEpochException ;
28
28
import org .apache .kafka .common .errors .ProducerFencedException ;
29
29
import org .apache .kafka .common .errors .TimeoutException ;
30
- import org .apache .kafka .common .serialization .ByteArraySerializer ;
31
30
import org .apache .kafka .common .test .api .ClusterConfigProperty ;
32
31
import org .apache .kafka .common .test .api .ClusterInstance ;
33
32
import org .apache .kafka .common .test .api .ClusterTest ;
42
41
import java .util .Collections ;
43
42
import java .util .HashMap ;
44
43
import java .util .Map ;
45
- import java .util .Properties ;
46
44
import java .util .concurrent .ExecutionException ;
47
45
48
46
import static org .junit .jupiter .api .Assertions .assertInstanceOf ;
@@ -68,22 +66,16 @@ public class AdminFenceProducersTest {
68
66
this .clusterInstance = clusterInstance ;
69
67
}
70
68
71
- private KafkaProducer <byte [], byte []> createProducer () {
72
- Properties config = new Properties ();
73
- config .put (ProducerConfig .BOOTSTRAP_SERVERS_CONFIG , clusterInstance .bootstrapServers ());
74
- config .put (ProducerConfig .TRANSACTIONAL_ID_CONFIG , TXN_ID );
75
- config .put (ProducerConfig .TRANSACTION_TIMEOUT_CONFIG , "2000" );
76
- config .put (ProducerConfig .KEY_SERIALIZER_CLASS_CONFIG , ByteArraySerializer .class .getName ());
77
- config .put (ProducerConfig .VALUE_SERIALIZER_CLASS_CONFIG , ByteArraySerializer .class .getName ());
78
-
79
- return new KafkaProducer <>(config );
69
+ private Producer <byte [], byte []> createProducer () {
70
+ return clusterInstance .producer (Map .of (ProducerConfig .TRANSACTIONAL_ID_CONFIG , TXN_ID ,
71
+ ProducerConfig .TRANSACTION_TIMEOUT_CONFIG , "2000" ));
80
72
}
81
73
82
74
@ ClusterTest
83
75
void testFenceAfterProducerCommit () throws Exception {
84
76
clusterInstance .createTopic (TOPIC_NAME , 1 , (short ) 1 );
85
77
86
- try (KafkaProducer <byte [], byte []> producer = createProducer ();
78
+ try (Producer <byte [], byte []> producer = createProducer ();
87
79
Admin adminClient = clusterInstance .admin ()) {
88
80
producer .initTransactions ();
89
81
producer .beginTransaction ();
@@ -125,7 +117,7 @@ void testFenceProducerTimeoutMs() {
125
117
void testFenceBeforeProducerCommit () throws Exception {
126
118
clusterInstance .createTopic (TOPIC_NAME , 1 , (short ) 1 );
127
119
128
- try (KafkaProducer <byte [], byte []> producer = createProducer ();
120
+ try (Producer <byte [], byte []> producer = createProducer ();
129
121
Admin adminClient = clusterInstance .admin ()) {
130
122
131
123
producer .initTransactions ();
0 commit comments