weiqingy commented on code in PR #657: URL: https://github.com/apache/flink-agents/pull/657#discussion_r3314255806
########## runtime/src/test/java/org/apache/flink/agents/runtime/memory/ShortTermMemoryTTLIntegrationTest.java: ########## @@ -0,0 +1,158 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.flink.agents.runtime.memory; + +import org.apache.flink.agents.api.AgentsExecutionEnvironment; +import org.apache.flink.agents.api.InputEvent; +import org.apache.flink.agents.api.OutputEvent; +import org.apache.flink.agents.api.agents.Agent; +import org.apache.flink.agents.api.agents.AgentExecutionOptions; +import org.apache.flink.agents.api.agents.ShortTermMemoryTtlUpdate; +import org.apache.flink.agents.api.agents.ShortTermMemoryTtlVisibility; +import org.apache.flink.agents.api.annotation.Action; +import org.apache.flink.agents.api.context.MemoryObject; +import org.apache.flink.agents.api.context.RunnerContext; +import org.apache.flink.agents.plan.AgentConfiguration; +import org.apache.flink.streaming.api.datastream.DataStream; +import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** Integration test for Short-Term Memory TTL functionality. */ +class ShortTermMemoryTTLIntegrationTest { + + private static final String MEMORY_KEY = "test_key"; + + private static final class TestInput { + public String eventKey; + public long sleepMs; + + private TestInput() {} + + private TestInput(String eventKey, long sleepMs) { + this.eventKey = eventKey; + this.sleepMs = sleepMs; + } + } + + public static class TTLTestAgent extends Agent { + + @Action(listenEventTypes = {InputEvent.EVENT_TYPE}) + public static void input(org.apache.flink.agents.api.Event event, RunnerContext ctx) + throws Exception { + InputEvent inputEvent = (InputEvent) event; + TestInput input = (TestInput) inputEvent.getInput(); + + MemoryObject shortTermMemory = ctx.getShortTermMemory(); + MemoryObject memoryObject = shortTermMemory.get(input.eventKey); + + Object existingValue = null; + int currentCount = 0; + if (memoryObject != null && !memoryObject.isNestedObject()) { + existingValue = memoryObject.getValue(); + if (existingValue instanceof Integer) { + currentCount = (Integer) existingValue; + } else if (existingValue instanceof Number) { + currentCount = ((Number) existingValue).intValue(); + } + } + + shortTermMemory.set(input.eventKey, currentCount + 1); + Thread.sleep(input.sleepMs); + ctx.sendEvent( + new OutputEvent( + input.eventKey + "|" + (existingValue == null ? "NEW" : "EXISTING"))); + } + } + + @Test + void testTTLConfigurationNotApplied() throws Exception { Review Comment: Nit: testTTLConfigurationNotApplied vs testTTLConfigurationApplied (line 109) is a bit misleading — TTL is configured in both; what differs is whether enough time elapsed for entries to expire (sleep_ms=0 vs 2000). Names like testValueStillVisibleBeforeTTLExpiry / testValueExpiresAfterTTL would express the actual assertion. Same suggestion for the Python mirror in short_term_memory_ttl_test.py:126,159. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
