Skip to content

Commit

Permalink
Create v3
Browse files Browse the repository at this point in the history
  • Loading branch information
philipp94831 committed Apr 5, 2024
1 parent 6d21657 commit 3597a20
Show file tree
Hide file tree
Showing 4 changed files with 337 additions and 337 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

package com.bakdata.kafka;

import com.google.common.annotations.VisibleForTesting;
import java.time.Duration;
import java.util.function.Consumer;
import java.util.function.Supplier;
Expand Down Expand Up @@ -74,11 +75,16 @@ private static boolean isStaticMembershipDisabled(final StreamsConfig config) {
}

CloseOptions createCloseOptions(final StreamsConfig config) {
final boolean staticMembershipDisabled = isStaticMembershipDisabled(config);
final boolean leaveGroup = staticMembershipDisabled || this.volatileGroupInstanceId;
final boolean leaveGroup = this.shouldLeaveGroup(config);
return new CloseOptions().leaveGroup(leaveGroup).timeout(this.closeTimeout);
}

@VisibleForTesting
boolean shouldLeaveGroup(final StreamsConfig config) {
final boolean staticMembershipDisabled = isStaticMembershipDisabled(config);
return staticMembershipDisabled || this.volatileGroupInstanceId;
}

void onStart(final KafkaStreams streams) {
this.onStart.accept(streams);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* MIT License
*
* Copyright (c) 2024 bakdata
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package com.bakdata.kafka;

import static java.util.Collections.emptyMap;
import static org.assertj.core.api.Assertions.assertThat;

import java.util.Map;
import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.apache.kafka.streams.StreamsConfig;
import org.junit.jupiter.api.Test;

public class StreamsExecutionOptionsTest {

@Test
void shouldLeaveGroup() {
final StreamsExecutionOptions options = StreamsExecutionOptions.builder()
.build();
assertThat(options.shouldLeaveGroup(new StreamsConfig(emptyMap()))).isTrue();

Check failure on line 41 in streams-bootstrap/src/test/java/com/bakdata/kafka/StreamsExecutionOptionsTest.java

View workflow job for this annotation

GitHub Actions / JUnit Test Report

StreamsExecutionOptionsTest.shouldLeaveGroup()

org.apache.kafka.common.config.ConfigException: Missing required configuration "application.id" which has no default value.
Raw output
org.apache.kafka.common.config.ConfigException: Missing required configuration "application.id" which has no default value.
	at app//org.apache.kafka.common.config.ConfigDef.parseValue(ConfigDef.java:496)
	at app//org.apache.kafka.common.config.ConfigDef.parse(ConfigDef.java:486)
	at app//org.apache.kafka.common.config.AbstractConfig.<init>(AbstractConfig.java:112)
	at app//org.apache.kafka.common.config.AbstractConfig.<init>(AbstractConfig.java:145)
	at app//org.apache.kafka.streams.StreamsConfig.<init>(StreamsConfig.java:1351)
	at app//org.apache.kafka.streams.StreamsConfig.<init>(StreamsConfig.java:1346)
	at app//com.bakdata.kafka.StreamsExecutionOptionsTest.shouldLeaveGroup(StreamsExecutionOptionsTest.java:41)
	at java.base@11.0.22/java.lang.reflect.Method.invoke(Method.java:566)
	at java.base@11.0.22/java.util.ArrayList.forEach(ArrayList.java:1541)
	at java.base@11.0.22/java.util.ArrayList.forEach(ArrayList.java:1541)
}

@Test
void shouldNotLeaveGroup() {
final StreamsExecutionOptions options = StreamsExecutionOptions.builder()
.volatileGroupInstanceId(false)
.build();
assertThat(options.shouldLeaveGroup(new StreamsConfig(Map.of(

Check failure on line 49 in streams-bootstrap/src/test/java/com/bakdata/kafka/StreamsExecutionOptionsTest.java

View workflow job for this annotation

GitHub Actions / JUnit Test Report

StreamsExecutionOptionsTest.shouldNotLeaveGroup()

org.apache.kafka.common.config.ConfigException: Missing required configuration "application.id" which has no default value.
Raw output
org.apache.kafka.common.config.ConfigException: Missing required configuration "application.id" which has no default value.
	at app//org.apache.kafka.common.config.ConfigDef.parseValue(ConfigDef.java:496)
	at app//org.apache.kafka.common.config.ConfigDef.parse(ConfigDef.java:486)
	at app//org.apache.kafka.common.config.AbstractConfig.<init>(AbstractConfig.java:112)
	at app//org.apache.kafka.common.config.AbstractConfig.<init>(AbstractConfig.java:145)
	at app//org.apache.kafka.streams.StreamsConfig.<init>(StreamsConfig.java:1351)
	at app//org.apache.kafka.streams.StreamsConfig.<init>(StreamsConfig.java:1346)
	at app//com.bakdata.kafka.StreamsExecutionOptionsTest.shouldNotLeaveGroup(StreamsExecutionOptionsTest.java:49)
	at java.base@11.0.22/java.lang.reflect.Method.invoke(Method.java:566)
	at java.base@11.0.22/java.util.ArrayList.forEach(ArrayList.java:1541)
	at java.base@11.0.22/java.util.ArrayList.forEach(ArrayList.java:1541)
ConsumerConfig.GROUP_INSTANCE_ID_CONFIG, "foo"
)))).isFalse();
}

@Test
void shouldLeaveGroupWithVolatileGroupId() {
final StreamsExecutionOptions options = StreamsExecutionOptions.builder()
.volatileGroupInstanceId(true)
.build();
assertThat(options.shouldLeaveGroup(new StreamsConfig(Map.of(

Check failure on line 59 in streams-bootstrap/src/test/java/com/bakdata/kafka/StreamsExecutionOptionsTest.java

View workflow job for this annotation

GitHub Actions / JUnit Test Report

StreamsExecutionOptionsTest.shouldLeaveGroupWithVolatileGroupId()

org.apache.kafka.common.config.ConfigException: Missing required configuration "application.id" which has no default value.
Raw output
org.apache.kafka.common.config.ConfigException: Missing required configuration "application.id" which has no default value.
	at app//org.apache.kafka.common.config.ConfigDef.parseValue(ConfigDef.java:496)
	at app//org.apache.kafka.common.config.ConfigDef.parse(ConfigDef.java:486)
	at app//org.apache.kafka.common.config.AbstractConfig.<init>(AbstractConfig.java:112)
	at app//org.apache.kafka.common.config.AbstractConfig.<init>(AbstractConfig.java:145)
	at app//org.apache.kafka.streams.StreamsConfig.<init>(StreamsConfig.java:1351)
	at app//org.apache.kafka.streams.StreamsConfig.<init>(StreamsConfig.java:1346)
	at app//com.bakdata.kafka.StreamsExecutionOptionsTest.shouldLeaveGroupWithVolatileGroupId(StreamsExecutionOptionsTest.java:59)
	at java.base@11.0.22/java.lang.reflect.Method.invoke(Method.java:566)
	at java.base@11.0.22/java.util.ArrayList.forEach(ArrayList.java:1541)
	at java.base@11.0.22/java.util.ArrayList.forEach(ArrayList.java:1541)
ConsumerConfig.GROUP_INSTANCE_ID_CONFIG, "foo"
)))).isTrue();
}
}
Loading

0 comments on commit 3597a20

Please sign in to comment.