Skip to content

Instantly share code, notes, and snippets.

@zhenik
zhenik / blog-testing-06.java
Last active June 19, 2019 12:30
Gist for blog: Testing kafka based applications
jsonServer =
new GenericContainer("zhenik/json-server")
.withExposedPorts(80)
// all containers put in same network
.withNetwork(network)
.withEnv("ID_MAP", "id")
// all containers put in same network
.withNetworkAliases("json-server")
// mount volume
.withClasspathResourceMapping(
@zhenik
zhenik / blog-testing-05.java
Created June 18, 2019 13:42
Gist for blog: Testing Kafka based application
/**
* Base test abstract class contains setup to
* initialize testing environment.
*/
public abstract class ContainersTestBaseIT {
// singleton containers https://www.testcontainers.org/test_framework_integration/manual_lifecycle_control/#singleton-containers
static {
final Network commonNetwork = Network.newNetwork();
setZookeeperAndKafka(commonNetwork);
@zhenik
zhenik / blog-testing-04.java
Last active June 18, 2019 06:44
Gist for blog: Testing Kafka based applications
public class ApplicationIT {
@ClassRule
public static final EmbeddedSingleNodeKafkaCluster CLUSTER =
new EmbeddedSingleNodeKafkaCluster();
@Test
public void clusterIsRunning() {
assertTrue(CLUSTER.isRunning());
}
@zhenik
zhenik / blog-testing-03.java
Last active June 18, 2019 06:12
Gist for blog: Testing Kafka based application
@Test
public void testTopologyAvro_statefulProcessors() throws IOException, RestClientException {
/** Arrange */
final String storeName = "same-name";
final SpecificAvroSerde<Person> serde = new SpecificAvroSerde<>(schemaRegistryClient);
final Map<String, String> schema =
Collections.singletonMap(
AbstractKafkaAvroSerDeConfig.SCHEMA_REGISTRY_URL_CONFIG,
"wat-ever-url-anyway-it-is-mocked");
@zhenik
zhenik / blog-testing-02.java
Created June 18, 2019 06:06
Gist for blog: Testing Kafka based application
// stateful
public static Topology topologyCountUsersWithSameName(
String sourceTopic,
String sinkTopic,
final Serde<Person> personSerdes,
final String storeName) {
final StreamsBuilder builder = new StreamsBuilder();
builder.stream(sourceTopic, Consumed.with(Serdes.String(), personSerdes))
.groupBy((key, value) -> value.getName())
@zhenik
zhenik / blog-testing-01.java
Last active June 18, 2019 06:02
Testing Kafka based applications. Blog
private TopologyTestDriver testDriver;
private MockSchemaRegistryClient schemaRegistryClient;
@Before
public void start() {
schemaRegistryClient = new MockSchemaRegistryClient();
}
@After
public void tearDown() {
@zhenik
zhenik / DB_Example_.gitignore
Created September 21, 2016 14:57
Homework. Java week4 JDBC
# Created by .ignore support plugin (hsz.mobi)
### Maven template
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
@zhenik
zhenik / Ex 2
Created November 27, 2015 15:08
Examens
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringJoiner;
/**
* Created by NIK on 27.11.15.
*/
public class Main2 {
public static void main(String[] args) {
@zhenik
zhenik / Ex 1
Created November 27, 2015 15:06
Examens
import java.util.ArrayList;
import java.util.Arrays;
/**
* Created by NIK on 27.11.15.
*/
public class Main {
public static void main(String[] args) {