-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ASSERT TOPIC command (#9066)
* feat: add ASSERT TOPIC command * make timeout nonreserved * checkstyle * fix unit test * update cli * fix integration test * fix qtt * address review comments
- Loading branch information
Zara Lim
authored
Apr 28, 2022
1 parent
99f8186
commit cd5254f
Showing
21 changed files
with
681 additions
and
7 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
6 changes: 6 additions & 0 deletions
6
...java/io/confluent/ksql/cli/console/ConsoleTest.shouldPrintAssertTopicResult.approved.json
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,6 @@ | ||
[ { | ||
"@type" : "assert_topic", | ||
"statementText" : "statement", | ||
"topicName" : "name", | ||
"warnings" : [ ] | ||
} ] |
2 changes: 2 additions & 0 deletions
2
...a/io/confluent/ksql/cli/console/ConsoleTest.shouldPrintAssertTopicResult.approved.tabular
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,2 @@ | ||
|
||
Topic name exists. |
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
85 changes: 85 additions & 0 deletions
85
ksqldb-parser/src/main/java/io/confluent/ksql/parser/tree/AssertTopic.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,85 @@ | ||
/* | ||
* Copyright 2022 Confluent Inc. | ||
* | ||
* Licensed under the Confluent Community License (the "License"; you may not use | ||
* this file except in compliance with the License. You may obtain a copy of the | ||
* License at | ||
* | ||
* http://www.confluent.io/confluent-community-license | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package io.confluent.ksql.parser.tree; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import com.google.errorprone.annotations.Immutable; | ||
import io.confluent.ksql.execution.expression.tree.Literal; | ||
import io.confluent.ksql.execution.windows.WindowTimeClause; | ||
import io.confluent.ksql.parser.NodeLocation; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
@Immutable | ||
public class AssertTopic extends Statement { | ||
|
||
private final String topic; | ||
private final ImmutableMap<String, Literal> config; | ||
private final Optional<WindowTimeClause> timeout; | ||
|
||
public AssertTopic( | ||
final Optional<NodeLocation> location, | ||
final String topic, | ||
final Map<String, Literal> config, | ||
final Optional<WindowTimeClause> timeout | ||
) { | ||
super(location); | ||
this.topic = Objects.requireNonNull(topic, "topic"); | ||
this.config = ImmutableMap.copyOf(Objects.requireNonNull(config, "config")); | ||
this.timeout = Objects.requireNonNull(timeout, "timeout"); | ||
} | ||
|
||
public String getTopic() { | ||
return topic; | ||
} | ||
|
||
public Map<String, Literal> getConfig() { | ||
return config; | ||
} | ||
|
||
public Optional<WindowTimeClause> getTimeout() { | ||
return timeout; | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
final AssertTopic that = (AssertTopic) o; | ||
return topic.equals(that.topic) | ||
&& Objects.equals(config, that.config) | ||
&& timeout.equals(that.timeout); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(topic, config, timeout); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "AssertTopic{" | ||
+ "topic=" + topic | ||
+ ",config=" + config | ||
+ ",timeout=" + timeout | ||
+ '}'; | ||
} | ||
} |
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
57 changes: 57 additions & 0 deletions
57
ksqldb-parser/src/test/java/io/confluent/ksql/parser/tree/AssertTopicTest.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,57 @@ | ||
package io.confluent.ksql.parser.tree; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import com.google.common.testing.EqualsTester; | ||
import io.confluent.ksql.execution.windows.WindowTimeClause; | ||
import io.confluent.ksql.parser.NodeLocation; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.concurrent.TimeUnit; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.MockitoJUnit; | ||
/* | ||
* Copyright 2022 Confluent Inc. | ||
* | ||
* Licensed under the Confluent Community License (the "License"; you may not use | ||
* this file except in compliance with the License. You may obtain a copy of the | ||
* License at | ||
* | ||
* http://www.confluent.io/confluent-community-license | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
import org.mockito.junit.MockitoRule; | ||
|
||
public class AssertTopicTest { | ||
|
||
@Rule | ||
public final MockitoRule mockitoRule = MockitoJUnit.rule(); | ||
|
||
public static final NodeLocation SOME_LOCATION = new NodeLocation(0, 0); | ||
public static final NodeLocation OTHER_LOCATION = new NodeLocation(1, 0); | ||
private final String SOME_TOPIC = "TOPIC"; | ||
private final Map SOME_CONFIG = ImmutableMap.of("partitions", 1); | ||
private final WindowTimeClause SOME_TIMEOUT = new WindowTimeClause(5, TimeUnit.SECONDS); | ||
|
||
@Test | ||
public void shouldImplementHashCodeAndEquals() { | ||
new EqualsTester() | ||
.addEqualityGroup( | ||
new AssertTopic(Optional.empty(), SOME_TOPIC, SOME_CONFIG, Optional.of(SOME_TIMEOUT)), | ||
new AssertTopic(Optional.of(new NodeLocation(1, 1)), SOME_TOPIC, SOME_CONFIG, Optional.of(SOME_TIMEOUT))) | ||
.addEqualityGroup( | ||
new AssertTopic(Optional.empty(), "another topic", SOME_CONFIG, Optional.of(SOME_TIMEOUT))) | ||
.addEqualityGroup( | ||
new AssertTopic(Optional.empty(), SOME_TOPIC, ImmutableMap.of(), Optional.of(SOME_TIMEOUT))) | ||
.addEqualityGroup( | ||
new AssertTopic(Optional.empty(), SOME_TOPIC, SOME_CONFIG, Optional.empty())) | ||
.testEquals(); | ||
} | ||
|
||
} |
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
Oops, something went wrong.