You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@streampipes.apache.org by "tenthe (via GitHub)" <gi...@apache.org> on 2023/12/27 10:20:00 UTC

[PR] feat(#2374): Add suggestion to test processing elements

tenthe opened a new pull request, #2375:
URL: https://github.com/apache/streampipes/pull/2375

   <!--
     ~ 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.
     ~
     -->
     
     <!--
   Thanks for contributing! Here are some tips you can follow to help us incorporate your contribution quickly and easily:
   1. If this is your first time, please read our contributor guidelines:
       - https://streampipes.apache.org/getinvolved.html
       - https://cwiki.apache.org/confluence/display/STREAMPIPES/Getting+Started
   2. Make sure the PR title is formatted like: `[#<GitHub issue id>] PR title ...`
   3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., `[WIP][#<GitHub issue id>] PR title ...`.
   4. Please write your PR title to summarize what this PR proposes/fixes.
   5. Link the PR to the corresponding GitHub issue (if present) in the `Development` section in the right menu bar. 
   6. Be sure to keep the PR description updated to reflect all changes.
   7. If possible, provide a concise example to reproduce the issue for a faster review.
   8. Make sure tests pass via `mvn clean install`.
   9. (Optional) If the contribution is large, please file an Apache ICLA
       - http://apache.org/licenses/icla.pdf
   -->
   
   ### Purpose
   <!--
   Please clarify what changes you are proposing and describe how those changes will address the issue.
   Furthermore, describe potential consequences the changes might have.
   -->
   
   The current pull request introduces a prototype for unit testing processing elements in the `streampipes-processors-filter-jvm` module, specifically for the `NumericalFilterProcessor`.
   
   #### Proposal
   - Implemented a basic prototype allowing developers to test processing element configurations.
   - Used `Map<String, Object>` for user input and `List<Map<String, Object>>` for events.
   - Proposing a discussion on whether to keep the current data type approach for simplicity or consider alternatives.
   - A static class, `ProcessingElementTestExecutor`, is suggested to execute the actual tests.
   
   > [!IMPORTANT] 
   > This PR is not final; its purpose is to showcase the testing functionality and initiate a discussion on testing options.
   
   If you have any suggestions or opinions on the proposed approach, feel free to share them here.
   
   ### Remarks
   <!--
   Is there anything left we need to pay attention on?
   Are there some references that might be important? E.g. links to Confluence, or discussions
   on the mailing list or GitHub.
   -->
   PR introduces (a) breaking change(s): no
   
   PR introduces (a) deprecation(s): no
   


-- 
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: dev-unsubscribe@streampipes.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(#2374): Add suggestion to test processing elements

Posted by "tenthe (via GitHub)" <gi...@apache.org>.
tenthe commented on PR #2375:
URL: https://github.com/apache/streampipes/pull/2375#issuecomment-2083177795

   Hi @IsaakKrut,
   I have fixed the problem with the cyclic dependencies. I also fixed the checkstyle issues.
   
   Is it possible for you to extract the `TestConfigurationBuilder` into an own file?
   
   @pambrocio, I suggest that we clean up this branch and then merge it into dev.
   Based on these changes, you can customize your PRs as the API should now be cleaner.
   And we can then use your feedback to further improve the testing API for processors.
   Is that ok for you?
   
   Cheers,
   Philipp


-- 
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: dev-unsubscribe@streampipes.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(#2374): Add suggestion to test processing elements

Posted by "tenthe (via GitHub)" <gi...@apache.org>.
tenthe commented on PR #2375:
URL: https://github.com/apache/streampipes/pull/2375#issuecomment-2038972783

   Hi @IsaakKrut,
   
   my suggestion would be that you try to write a test for another processor with this "new" API.
   And then, based on this experience, we discuss and try to design the API and the implementation for the "ProcessingElementTestExecutor" together. 
   What do you think of this idea?
   
   I think the biggest challenge will be to handle all the different types of static properties that a user can enter to configure the processor. I think one or two more sample tests would help to get a better understanding of what the best solution should look like.
   
   Cheers,
   Philipp


-- 
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: dev-unsubscribe@streampipes.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(#2374): Add suggestion to test processing elements

Posted by "pambrocio (via GitHub)" <gi...@apache.org>.
pambrocio commented on PR #2375:
URL: https://github.com/apache/streampipes/pull/2375#issuecomment-2076694365

   Hi @tenthe  @IsaakKrut, 
   
   I would love to contribute to this effort. I have already migrated the classes stated in https://github.com/apache/streampipes/issues/2538 to JUnit 5,  I am quite unclear on what needs to be done for my work to integrate into this effort.
   
   Thanks,
   Pambrocio


-- 
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: dev-unsubscribe@streampipes.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(#2374): Add suggestion to test processing elements

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #2375:
URL: https://github.com/apache/streampipes/pull/2375#issuecomment-1897608955

   Hello there :wave:<br> <br> We noticed that it's been some time since activity occurred on your pull request :thinking:. In order to keep things moving forward, we're marking this PR as _stale_ and giving you 7 days to respond before it's automatically closed :alarm_clock:.<br> <br> Please take a moment to review your pull request and make any necessary updates or changes :man_technologist:. If you need more time or have any questions, please don't hesitate to let us know :speech_balloon:.<br> <br> Thank you for your contributions to our project, and we look forward to hearing back from you soon :pray:.


-- 
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: dev-unsubscribe@streampipes.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(#2374): Add suggestion to test processing elements

Posted by "tenthe (via GitHub)" <gi...@apache.org>.
tenthe commented on PR #2375:
URL: https://github.com/apache/streampipes/pull/2375#issuecomment-2078737994

   > Hi @tenthe @IsaakKrut,
   > 
   > I would love to contribute to this effort. I have already migrated the classes stated in #2538 to JUnit 5, I am quite unclear on what needs to be done for my work to integrate into this effort.
   > 
   > Thanks, Pambrocio
   
   Hi @pambrocio,
   thanks a lot for your PRs. I do not have much time this week, I'll have a detailed look at them next week.
   
   Cheers,
   Philipp


-- 
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: dev-unsubscribe@streampipes.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(#2374): Add suggestion to test processing elements

Posted by "tenthe (via GitHub)" <gi...@apache.org>.
tenthe merged PR #2375:
URL: https://github.com/apache/streampipes/pull/2375


-- 
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: dev-unsubscribe@streampipes.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(#2374): Add suggestion to test processing elements

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #2375:
URL: https://github.com/apache/streampipes/pull/2375#issuecomment-1909196774

   Hello there :wave:<br> <br> Unfortunately, we didn't hear back from you regarding your pull request, so we're closing it now. Don't worry, you can always reopen the PR at any time if you wish to continue working on it :raised_hands:.<br> <br> Please note that the branch associated with this pull request will not be deleted, so you can still access your changes and continue to work on them as needed :computer:.<br> <br> Thank you for your contributions to our project, and we hope to see you again soon!


-- 
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: dev-unsubscribe@streampipes.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(#2374): Add suggestion to test processing elements

Posted by "bossenti (via GitHub)" <gi...@apache.org>.
bossenti commented on code in PR #2375:
URL: https://github.com/apache/streampipes/pull/2375#discussion_r1553003136


##########
streampipes-extensions/streampipes-processors-filters-jvm/src/test/java/org/apache/streampipes/processors/filters/jvm/processor/numericalfilter/ProcessingElementTestExecutor.java:
##########
@@ -0,0 +1,159 @@
+/*
+ * 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.streampipes.processors.filters.jvm.processor.numericalfilter;
+
+import org.apache.streampipes.extensions.api.pe.IStreamPipesDataProcessor;
+import org.apache.streampipes.extensions.api.pe.param.IDataProcessorParameters;
+import org.apache.streampipes.extensions.api.pe.routing.SpOutputCollector;
+import org.apache.streampipes.manager.template.DataProcessorTemplateHandler;
+import org.apache.streampipes.model.graph.DataProcessorInvocation;
+import org.apache.streampipes.model.runtime.Event;
+import org.apache.streampipes.model.runtime.EventFactory;
+import org.apache.streampipes.model.runtime.SchemaInfo;
+import org.apache.streampipes.model.runtime.SourceInfo;
+import org.apache.streampipes.model.template.PipelineElementTemplate;
+import org.apache.streampipes.model.template.PipelineElementTemplateConfig;
+import org.apache.streampipes.sdk.extractor.ProcessingElementParameterExtractor;
+
+import org.mockito.ArgumentCaptor;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.IntStream;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+public class ProcessingElementTestExecutor {
+
+  /**
+   * This method is used to run a data processor with a given configuration and a list of input events.
+   * It then verifies the output events against the expected output events.
+   *
+   * @param processor            The data processor under test.
+   * @param userConfiguration    The user input configuration for the processor.
+   * @param inputEvents          The list of input events to be processed.
+   * @param expectedOutputEvents The list of expected output events.
+   */
+  public static void run(
+      IStreamPipesDataProcessor processor,
+      Map<String, Object> userConfiguration,
+      List<Map<String, Object>> inputEvents,
+      List<Map<String, Object>> expectedOutputEvents
+  ) {
+
+    // initialize the extractor with the provided configuration of the user input
+    var e = getProcessingElementParameterExtractor(processor, userConfiguration);
+    var mockParams = mock(IDataProcessorParameters.class);
+    when(mockParams.extractor()).thenReturn(e);
+
+
+    // calls the onPipelineStarted method of the processor to initialize it
+    processor.onPipelineStarted(mockParams, null, null);
+
+    // mock the output collector to capture the output events and validate the results later
+    var mockCollector = mock(SpOutputCollector.class);
+    var spOutputCollectorCaptor = ArgumentCaptor.forClass(Event.class);
+
+
+    // Iterate over all input events and call the onEvent method of the processor
+    for (Map<String, Object> inputRawEvent : inputEvents) {
+      processor.onEvent(getEvent(inputRawEvent), mockCollector);
+    }
+
+    // Validate the output of the processor
+    verify(mockCollector, times(expectedOutputEvents.size())).collect(spOutputCollectorCaptor.capture());
+    var resultingEvents = spOutputCollectorCaptor.getAllValues();
+    IntStream.range(0, expectedOutputEvents.size())
+             .forEach(i -> assertEquals(
+                 expectedOutputEvents.get(i),
+                 resultingEvents.get(i)
+                                .getRaw()
+             ));
+
+    // vlaidate that the processor is stopped correctly

Review Comment:
   ```suggestion
       // validate that the processor is stopped correctly
   ```



##########
streampipes-extensions/streampipes-processors-filters-jvm/src/test/java/org/apache/streampipes/processors/filters/jvm/processor/numericalfilter/ProcessingElementTestExecutor.java:
##########
@@ -0,0 +1,159 @@
+/*
+ * 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.streampipes.processors.filters.jvm.processor.numericalfilter;
+
+import org.apache.streampipes.extensions.api.pe.IStreamPipesDataProcessor;
+import org.apache.streampipes.extensions.api.pe.param.IDataProcessorParameters;
+import org.apache.streampipes.extensions.api.pe.routing.SpOutputCollector;
+import org.apache.streampipes.manager.template.DataProcessorTemplateHandler;
+import org.apache.streampipes.model.graph.DataProcessorInvocation;
+import org.apache.streampipes.model.runtime.Event;
+import org.apache.streampipes.model.runtime.EventFactory;
+import org.apache.streampipes.model.runtime.SchemaInfo;
+import org.apache.streampipes.model.runtime.SourceInfo;
+import org.apache.streampipes.model.template.PipelineElementTemplate;
+import org.apache.streampipes.model.template.PipelineElementTemplateConfig;
+import org.apache.streampipes.sdk.extractor.ProcessingElementParameterExtractor;
+
+import org.mockito.ArgumentCaptor;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.IntStream;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+public class ProcessingElementTestExecutor {
+
+  /**
+   * This method is used to run a data processor with a given configuration and a list of input events.
+   * It then verifies the output events against the expected output events.
+   *
+   * @param processor            The data processor under test.
+   * @param userConfiguration    The user input configuration for the processor.
+   * @param inputEvents          The list of input events to be processed.
+   * @param expectedOutputEvents The list of expected output events.
+   */
+  public static void run(
+      IStreamPipesDataProcessor processor,
+      Map<String, Object> userConfiguration,
+      List<Map<String, Object>> inputEvents,
+      List<Map<String, Object>> expectedOutputEvents
+  ) {
+
+    // initialize the extractor with the provided configuration of the user input
+    var e = getProcessingElementParameterExtractor(processor, userConfiguration);

Review Comment:
   ```suggestion
       var extractor = getProcessingElementParameterExtractor(processor, userConfiguration);
   ```



-- 
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: dev-unsubscribe@streampipes.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(#2374): Add suggestion to test processing elements

Posted by "IsaakKrut (via GitHub)" <gi...@apache.org>.
IsaakKrut commented on PR #2375:
URL: https://github.com/apache/streampipes/pull/2375#issuecomment-2037668343

   @tenthe do you have examples of tests or processors that use selector prefix or event schema? Are there any that use multiple prefixes? Trying to understand which processors require something extra for testing


-- 
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: dev-unsubscribe@streampipes.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(#2374): Add suggestion to test processing elements

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #2375: feat(#2374): Add suggestion to test processing elements
URL: https://github.com/apache/streampipes/pull/2375


-- 
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: dev-unsubscribe@streampipes.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org