-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add e2e tests for gateway with Pulsar #602
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
73 changes: 73 additions & 0 deletions
73
...test/java/ai/langstream/apigateway/websocket/handlers/KafkaProduceConsumeHandlerTest.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,73 @@ | ||
/* | ||
* Copyright DataStax, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package ai.langstream.apigateway.websocket.handlers; | ||
|
||
import ai.langstream.api.model.StreamingCluster; | ||
import ai.langstream.api.storage.ApplicationStore; | ||
import ai.langstream.apigateway.config.GatewayTestAuthenticationProperties; | ||
import ai.langstream.kafka.extensions.KafkaContainerExtension; | ||
import java.util.Map; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
import org.springframework.boot.test.context.TestConfiguration; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Primary; | ||
|
||
public class KafkaProduceConsumeHandlerTest extends ProduceConsumeHandlerTest { | ||
|
||
@RegisterExtension | ||
static KafkaContainerExtension kafkaContainer = new KafkaContainerExtension(); | ||
|
||
@Override | ||
protected StreamingCluster getStreamingCluster() { | ||
return new StreamingCluster( | ||
"kafka", | ||
Map.of( | ||
"admin", | ||
Map.of( | ||
"bootstrap.servers", | ||
kafkaContainer.getBootstrapServers(), | ||
"default.api.timeout.ms", | ||
5000))); | ||
} | ||
|
||
@TestConfiguration | ||
public static class WebSocketTestConfig { | ||
|
||
@Bean | ||
@Primary | ||
public ApplicationStore store() { | ||
String instanceYaml = | ||
""" | ||
instance: | ||
streamingCluster: | ||
type: "kafka" | ||
configuration: | ||
admin: | ||
bootstrap.servers: "%s" | ||
computeCluster: | ||
type: "none" | ||
""" | ||
.formatted(kafkaContainer.getBootstrapServers()); | ||
return getMockedStore(instanceYaml); | ||
} | ||
|
||
@Bean | ||
@Primary | ||
public GatewayTestAuthenticationProperties gatewayTestAuthenticationProperties() { | ||
return getGatewayTestAuthenticationProperties(); | ||
} | ||
} | ||
} |
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
67 changes: 67 additions & 0 deletions
67
...y/src/test/java/ai/langstream/apigateway/websocket/handlers/PulsarContainerExtension.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,67 @@ | ||
/* | ||
* Copyright DataStax, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package ai.langstream.apigateway.websocket.handlers; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.junit.jupiter.api.extension.AfterAllCallback; | ||
import org.junit.jupiter.api.extension.BeforeAllCallback; | ||
import org.junit.jupiter.api.extension.ExtensionContext; | ||
import org.testcontainers.containers.Network; | ||
import org.testcontainers.containers.PulsarContainer; | ||
import org.testcontainers.utility.DockerImageName; | ||
|
||
@Slf4j | ||
public class PulsarContainerExtension implements BeforeAllCallback, AfterAllCallback { | ||
private PulsarContainer pulsarContainer; | ||
|
||
private Network network; | ||
|
||
@Override | ||
public void afterAll(ExtensionContext extensionContext) { | ||
if (pulsarContainer != null) { | ||
pulsarContainer.close(); | ||
} | ||
if (network != null) { | ||
network.close(); | ||
} | ||
} | ||
|
||
@Override | ||
public void beforeAll(ExtensionContext extensionContext) { | ||
network = Network.newNetwork(); | ||
pulsarContainer = | ||
new PulsarContainer(DockerImageName.parse("apachepulsar/pulsar:3.1.0")) | ||
.withNetwork(network) | ||
.withLogConsumer( | ||
outputFrame -> | ||
log.debug( | ||
"pulsar> {}", outputFrame.getUtf8String().trim())); | ||
// start Pulsar and wait for it to be ready to accept requests | ||
pulsarContainer.start(); | ||
} | ||
|
||
public String getBrokerUrl() { | ||
return pulsarContainer.getPulsarBrokerUrl(); | ||
} | ||
|
||
public String getHttpServiceUrl() { | ||
return pulsarContainer.getHttpServiceUrl(); | ||
} | ||
|
||
public PulsarContainer getPulsarContainer() { | ||
return pulsarContainer; | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please note that this dependency imports some version of the Pulsar client, is it polluting the classpath ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to be OK. Testcontainers uses the same shaded jar that the runtime uses.