-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
231 additions
and
48 deletions.
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
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
5 changes: 3 additions & 2 deletions
5
...kms-starter/src/main/java/com/transferwise/kafka/tkms/config/ITkmsKafkaAdminProvider.java
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 |
---|---|---|
@@ -1,11 +1,12 @@ | ||
package com.transferwise.kafka.tkms.config; | ||
|
||
import com.transferwise.kafka.tkms.api.TkmsShardPartition; | ||
import org.apache.kafka.clients.admin.Admin; | ||
|
||
public interface ITkmsKafkaAdminProvider { | ||
|
||
Admin getKafkaAdmin(); | ||
Admin getKafkaAdmin(TkmsShardPartition tkmsShardPartition); | ||
|
||
void closeKafkaAdmin(); | ||
void closeKafkaAdmin(TkmsShardPartition tkmsShardPartition); | ||
|
||
} |
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
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
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
78 changes: 78 additions & 0 deletions
78
...-starter/src/test/java/com/transferwise/kafka/tkms/MultiServerTopicValidationIntTest.java
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 |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package com.transferwise.kafka.tkms; | ||
|
||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
import com.transferwise.common.baseutils.transactionsmanagement.ITransactionsHelper; | ||
import com.transferwise.kafka.tkms.api.ITransactionalKafkaMessageSender; | ||
import com.transferwise.kafka.tkms.api.TkmsMessage; | ||
import com.transferwise.kafka.tkms.config.ITkmsKafkaProducerProvider; | ||
import com.transferwise.kafka.tkms.test.BaseIntTest; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.stream.Stream; | ||
import lombok.SneakyThrows; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
public class MultiServerTopicValidationIntTest extends BaseIntTest { | ||
|
||
@Autowired | ||
private ITransactionalKafkaMessageSender transactionalKafkaMessageSender; | ||
@Autowired | ||
private ITransactionsHelper transactionsHelper; | ||
@Autowired | ||
private ITkmsKafkaProducerProvider tkmsKafkaProducerProvider; | ||
|
||
@AfterEach | ||
public void cleanup() { | ||
super.cleanup(); | ||
|
||
tkmsProperties.getTopicValidation().setUseAdminClient(false); | ||
tkmsProperties.getTopicValidation().setTryToAutoCreateTopics(true); | ||
} | ||
|
||
private static Stream<Arguments> unknownTopicsMatrix() { | ||
return Stream.of( | ||
Arguments.of(true), | ||
Arguments.of(false) | ||
); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("unknownTopicsMatrix") | ||
@SneakyThrows | ||
void sendingToUnknownTopicWillBePreventedWhenTopicAutoCreationIsDisabled(boolean useAdminClient) { | ||
tkmsProperties.getTopicValidation().setUseAdminClient(useAdminClient); | ||
|
||
final var notExistingTopic = "NotExistingTopic"; | ||
final var existingTopicInKafka2 = "TestTopicInAnotherServer"; | ||
|
||
assertThatThrownBy(() -> sendMessage(notExistingTopic, null)).hasMessageContaining(notExistingTopic); | ||
|
||
sendMessage("TestTopic", null); | ||
sendMessage("TestTopic", tkmsProperties.getDefaultShard()); | ||
|
||
assertThatThrownBy(() -> sendMessage(existingTopicInKafka2, null)).hasMessageContaining(existingTopicInKafka2); | ||
|
||
sendMessage(existingTopicInKafka2, 2); | ||
} | ||
|
||
protected void sendMessage(String topic, Integer shard) { | ||
try { | ||
transactionsHelper.withTransaction().run(() -> { | ||
var message = new TkmsMessage().setTopic(topic).setValue("Stuff".getBytes(StandardCharsets.UTF_8)); | ||
if (shard != null) { | ||
message.setShard(shard); | ||
} | ||
transactionalKafkaMessageSender.sendMessage(message); | ||
}); | ||
} catch (Exception e) { | ||
throw new RuntimeException("Sending message to topic '" + topic + "' and shard " + shard + " failed."); | ||
} finally { | ||
// Stop spam of metadata errors. | ||
tkmsKafkaProducerProvider.closeKafkaProducersForTopicValidation(); | ||
} | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,7 +61,6 @@ public void setup() { | |
} | ||
meterCache.clear(); | ||
|
||
|
||
TkmsClockHolder.reset(); | ||
} | ||
|
||
|
Oops, something went wrong.