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
@Component | |
public class KafkaListenerConsumer { | |
@KafkaListener( | |
concurrency = "2", | |
topics = "${spring.kafka.consumer.topic}", groupId = "${spring.kafka.consumer.group-id}") | |
public void processMessage(List<Message<String>> content) { | |
// processing logic comes here | |
} | |
} |
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
@Component | |
public class KafkaListenerConsumer { | |
@KafkaListener(topics = "${spring.kafka.consumer.topic}", groupId = "${spring.kafka.consumer.group-id}") | |
public void processMessage(List<Message<String>> content) { | |
// processing logic comes here | |
} | |
} |
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
// given | |
Option<String> empty = Option.none(); | |
// this one fails | |
assumeThat(empty).isDefined(); | |
// so the assertion won't be checked and test is ignored | |
assertThat(empty).contains("yay!); | |
// given | |
Either<String, Integer> value = Either.right(42); | |
// this oone passes |
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
Either<Integer, String> actualLeft = Either.left(42); | |
assertThat(actualLeft).hasLeftValueSatisfying(it -> Assertions.assertThat(it).isEqualTo(42)); | |
Either<Integer, String> actualRight = Either.right("42"); | |
assertThat(actualRight).hasRightValueSatisfying(it -> Assertions.assertThat(it).isEqualTo("42")); |
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
// given | |
private static final Tuple2<String, String> FRODO = Tuple.of("hobbit", "frodo"); | |
private static final Tuple2<String, String> SAM = Tuple.of("hobbit", "sam"); | |
private static final Tuple2<String, String> GIMLI = Tuple.of("dwarf", "gimli"); | |
private static final Tuple2<String, String> LEGOLAS = Tuple.of("elf", "legolas"); | |
private static final Multimap<String, String> RACES = | |
HashMultimap.withSeq().ofEntries(FRODO, SAM, GIMLI); | |
private static final BiConsumer<String, String> OK_CONSUMER = (key, value) -> Assertions.assertThat(key).isLowerCase(); |
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
assertThat(PERSONS).hasEntrySatisfying("frodo", new Condition<String>() { | |
@Override | |
public boolean matches(String value) { | |
return value.equals("hobbit"); | |
} | |
}); |
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
// given | |
private static final Map<String, String> PERSONS_ORDERED = TreeMap.ofEntries(GIMLI, FRODO); | |
// in test | |
assertThat(PERSONS_ORDERED).containsExactly(FRODO, GIMLI); |
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
// given | |
private static final Tuple2<String, String> FRODO = Tuple.of("frodo", "hobbit"); | |
private static final Tuple2<String, String> GIMLI = Tuple.of("gimli", "dwarf"); | |
private static final Tuple2<String, String> LEGOLAS = Tuple.of("legolas", "elf"); | |
private static final Map<String, String> PERSONS = List.of(FRODO, GIMLI, LEGOLAS).toMap(tup -> tup); | |
// somewhere in tests | |
assertThat(PERSONS) | |
.containsOnly(List.of(FRODO, GIMLI, LEGOLAS)) |
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
public Option<TokenTTL> fetchRemainingTTL(AppId appId, UserId userId) { | |
ResultSet resultSet = cassandraOperations | |
.getCqlOperations() | |
.queryForResultSet("SELECT TTL(remote_ip) AS token_ttl from tokens WHERE app_id = ? AND user_id = ?", appId, userId); | |
return Option.of(resultSet.one()).map(row -> row.get("token_ttl", TokenTTL.class)); | |
} |
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
class MyConfig extends AbstractCassandraConfiguration { | |
@Override | |
protected ClusterBuilderConfigurer getClusterBuilderConfigurer() { | |
return clusterBuilder -> { | |
clusterBuilder.getConfiguration() | |
.getCodecRegistry() | |
.register(ApplicationIdCodec.instance) | |
.register(UserIdCodec.instance); | |
return clusterBuilder; |