Skip to content
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 test for topic producer #736

Merged
merged 1 commit into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ public void testProcessor() {
"{\"record\":{\"key\":null,\"value\":\"my-value!!super secret value\","
+ "\"headers\":{\"langstream-client-session-id\":\"s1\"}}"));

output =
executeCommandOnClient(
("bin/langstream gateway consume %s topic-producer --position earliest -n 1 --connect-timeout 30")
.formatted(applicationId)
.split(" "));
log.info("Output2: {}", output);
Assertions.assertTrue(
output.contains(
"{\"record\":{\"key\":null,\"value\":\"my-value test-topic-producer\",\"headers\":{}}"));

updateLocalApplicationAndAwaitReady(
tenant,
applicationId,
Expand All @@ -77,7 +87,7 @@ public void testProcessor() {
+ "30 -p sessionId=s2")
.formatted(applicationId)
.split(" "));
log.info("Output2: {}", output);
log.info("Output3: {}", output);
Assertions.assertTrue(
output.contains(
"{\"record\":{\"key\":null,\"value\":\"my-value!!super secret value - changed\","
Expand All @@ -89,6 +99,7 @@ public void testProcessor() {
log.info("all topics: {}", topics);
Assertions.assertTrue(topics.contains("ls-test-topic0"));
Assertions.assertFalse(topics.contains("ls-test-topic1"));
Assertions.assertTrue(topics.contains("ls-test-topic-producer"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,7 @@ gateways:
filters:
headers:
- key: langstream-client-session-id
value-from-parameters: sessionId
value-from-parameters: sessionId
- id: topic-producer
type: consume
topic: ls-test-topic-producer
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ topics:
type: string
keySchema:
type: string
- name: ls-test-topic-producer
creation-mode: create-if-not-exists
schema:
type: string
keySchema:
type: string
pipeline:
- name: "Process using Python"
resources:
Expand All @@ -44,4 +50,4 @@ pipeline:
output: ls-test-topic1
configuration:
secret_value: "${secrets.secret1.value-key}"
className: example.Exclamation
className: example.Exclamation
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def init(self, config, context: AgentContext):

def process(self, record):
logging.info("Processing record" + str(record))
self.context.get_topic_producer().write("ls-test-topic-producer", {"value": record.value() + " test-topic-producer"}).result()
directory = self.context.get_persistent_state_directory()
counter_file = os.path.join(directory, "counter.txt")
counter = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ async def agent_info(self, _, __):
async def poll_topic_producer_records(self, context):
while True:
topic, record, future = await self.topic_producer_records.get()
schemas, grpc_record = self.to_grpc_record(record)
schemas, grpc_record = self.to_grpc_record(wrap_in_record(record))
for schema in schemas:
await context.write(TopicProducerResponse(schema=schema))
self.topic_producer_record_id += 1
Expand Down
Loading