From 4c178d16be8a3378ea2a1d992d2665effb05c6f7 Mon Sep 17 00:00:00 2001 From: baubakg Date: Wed, 25 Sep 2024 15:07:42 +0200 Subject: [PATCH 1/6] Corrected test --- .../tests/integro/phased/PhasedTestManagerTests.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/adobe/campaign/tests/integro/phased/PhasedTestManagerTests.java b/src/test/java/com/adobe/campaign/tests/integro/phased/PhasedTestManagerTests.java index da61c63e..09fe7f6c 100644 --- a/src/test/java/com/adobe/campaign/tests/integro/phased/PhasedTestManagerTests.java +++ b/src/test/java/com/adobe/campaign/tests/integro/phased/PhasedTestManagerTests.java @@ -14,6 +14,7 @@ import com.adobe.campaign.tests.integro.phased.data.*; import com.adobe.campaign.tests.integro.phased.data.befaft.PhasedSeries_M_SimpleClass; import com.adobe.campaign.tests.integro.phased.data.dp.*; +import com.adobe.campaign.tests.integro.phased.data.events.NI_Event1; import com.adobe.campaign.tests.integro.phased.data.events.TestSINGLEWithEvent_eventAsAnnotation; import com.adobe.campaign.tests.integro.phased.data.events.TestSINGLEWithEvent_eventAsExecProperty; import com.adobe.campaign.tests.integro.phased.data.events.TestShuffled_eventPassedAsExecutionVariable; @@ -1139,6 +1140,7 @@ public void testFetchProvidersSingle_asynchronousNonInterruptive() throws NoSuchMethodException, SecurityException { Phases.ASYNCHRONOUS.activate(); + //ConfigValueHandlerPhased.EVENTS_NONINTERRUPTIVE.activate(NI_Event1.class.getTypeName()); final Method l_myMethod1 = TestSINGLEWithEvent_eventAsAnnotation.class.getMethod("step1", String.class); final Method l_myMethod2 = TestSINGLEWithEvent_eventAsAnnotation.class.getMethod("step2", String.class); final Method l_myMethod3 = TestSINGLEWithEvent_eventAsAnnotation.class.getMethod("step3", String.class); @@ -1146,12 +1148,14 @@ public void testFetchProvidersSingle_asynchronousNonInterruptive() Object[] l_providerStep1 = PhasedTestManager.fetchProvidersSingle(l_myMethod1); assertThat("We should have a parameter for this method",l_providerStep1.length, equalTo(1)); + //System.out.println(PhasedEventManager.fetchEvent()); + assertThat("We should have the correct parameter for this method",l_providerStep1[0], equalTo(PhasedTestManager.STD_PHASED_GROUP_SINGLE)); - Object[] l_providerStep2 = PhasedTestManager.fetchProvidersSingle(l_myMethod1); + Object[] l_providerStep2 = PhasedTestManager.fetchProvidersSingle(l_myMethod2); assertThat("We should have a parameter for this method",l_providerStep2.length, equalTo(1)); - Object[] l_providerStep3 = PhasedTestManager.fetchProvidersSingle(l_myMethod1); + Object[] l_providerStep3 = PhasedTestManager.fetchProvidersSingle(l_myMethod3); assertThat("We should have a parameter for this method",l_providerStep3.length, equalTo(1)); From 4da4ee4ee2f3f9f1417eedd112bfc7ac1ab773ee Mon Sep 17 00:00:00 2001 From: baubakg Date: Fri, 27 Sep 2024 16:31:40 +0200 Subject: [PATCH 2/6] Fixed 201, where an exception is thown if the given event is not executable as an event. Also Fixed #193 the phase group will include the event --- .../integro/phased/PhasedEventManager.java | 76 ++++-- .../integro/phased/PhasedTestManager.java | 11 +- .../phased/PhasedTestManagerTests.java | 107 +++++++- .../phased/TestPhasedNonInterruptive.java | 241 +++++++++++++----- 4 files changed, 339 insertions(+), 96 deletions(-) diff --git a/src/main/java/com/adobe/campaign/tests/integro/phased/PhasedEventManager.java b/src/main/java/com/adobe/campaign/tests/integro/phased/PhasedEventManager.java index a4c98af5..cb63c847 100644 --- a/src/main/java/com/adobe/campaign/tests/integro/phased/PhasedEventManager.java +++ b/src/main/java/com/adobe/campaign/tests/integro/phased/PhasedEventManager.java @@ -25,8 +25,9 @@ public class PhasedEventManager { private static final Logger log = LogManager.getLogger(); - + static Map events = new HashMap<>(); private static ExecutorService eventExecutor = null; + private static List eventLogs = new ArrayList(); /** * Returns the declared event. if declared on the method. The declarations have the following precedence: @@ -35,11 +36,12 @@ public class PhasedEventManager { *
  • Declaration in @PhasedTest
  • *
  • When the property PHASED.EVENTS.NONINTERRUPTIVE is set
  • * Null is returned if no such declaration is present. + * * @param in_method The method we are examining * @return The event that is declared on the method. Null if there is no event declared for the method */ public static String fetchApplicableEvent(Method in_method) { - if (!PhasedTestManager.isPhasedTest(in_method) ) { + if (!PhasedTestManager.isPhasedTest(in_method)) { return null; } /* @@ -71,23 +73,53 @@ public static String fetchApplicableEvent(Method in_method) { ConfigValueHandlerPhased.EVENTS_NONINTERRUPTIVE.fetchValue(); */ - } - else if (in_method.getDeclaringClass().getDeclaredAnnotation(PhasedTest.class).eventClasses().length > 0) { + } else if (in_method.getDeclaringClass().getDeclaredAnnotation(PhasedTest.class).eventClasses().length > 0) { return in_method.getDeclaringClass().getDeclaredAnnotation(PhasedTest.class).eventClasses()[0]; } else if (ConfigValueHandlerPhased.EVENT_TARGET.isSet()) { - return PhasedTestManager.isPhasedTestTargetOfEvent(in_method) ? ConfigValueHandlerPhased.EVENTS_NONINTERRUPTIVE.fetchValue() : null; + return PhasedTestManager.isPhasedTestTargetOfEvent( + in_method) ? ConfigValueHandlerPhased.EVENTS_NONINTERRUPTIVE.fetchValue() : null; } else if (ConfigValueHandlerPhased.EVENTS_NONINTERRUPTIVE.isSet()) { return ConfigValueHandlerPhased.EVENTS_NONINTERRUPTIVE.fetchValue(); } return null; } - protected static enum EventMode {START, END}; + ; - static Map events = new HashMap<>(); + /** + * Returns the declared event. if declared on the method. The declarations have the following precedence: + *
      + *
    1. Declaration in @PhaseEvent
    2. + *
    3. Declaration in @PhasedTest
    4. + *
    5. When the property PHASED.EVENTS.NONINTERRUPTIVE is set
    6. + *
    Null is returned if no such declaration is present. + * + * @param in_scenario The class/scenario we are examining + * @return The event that is declared on the method. Null if there is no event declared for the method + */ + public static Class fetchApplicableEvent(Class in_scenario) { + Method l_foundMethod = Arrays.stream(in_scenario.getMethods()).filter(m -> fetchApplicableEvent(m) != null) + .findFirst().orElse(null); + if (l_foundMethod == null) { + return null; + } - private static List eventLogs = new ArrayList(); + try { + Class lr_eventClass = Class.forName(fetchApplicableEvent(l_foundMethod)); + + if (!NonInterruptiveEvent.class.isAssignableFrom(lr_eventClass)) { + throw new PhasedTestConfigurationException( + "The given event " + lr_eventClass.getTypeName() + " should extend the abstract class " + + NonInterruptiveEvent.class.getTypeName() + "."); + } + + return lr_eventClass; + } catch (ClassNotFoundException e) { + throw new PhasedTestConfigurationException( + "The given event " + fetchApplicableEvent(l_foundMethod) + " could not be found.", e); + } + } /** * Used for logging events @@ -112,7 +144,7 @@ protected static NonInterruptiveEvent startEvent(String in_event, String in_onAc if (eventExecutor == null) { eventExecutor = Executors.newSingleThreadExecutor(); } - log.info("Starting event {} for step {}.",in_event,in_onAccountOfStep); + log.info("Starting event {} for step {}.", in_event, in_onAccountOfStep); NonInterruptiveEvent nie = instantiateClassFromString(in_event); logEvent(EventMode.START, in_event, in_onAccountOfStep); events.put(in_onAccountOfStep, nie); @@ -135,14 +167,17 @@ private static NonInterruptiveEvent instantiateClassFromString(String in_event) Class eventClass = Class.forName(in_event); if (!NonInterruptiveEvent.class.isAssignableFrom(eventClass)) { - throw new PhasedTestConfigurationException("The given event "+in_event+ " should be a sub-class of the abstract class "+NonInterruptiveEvent.class.getTypeName()+"."); + throw new PhasedTestConfigurationException( + "The given event " + in_event + " should be a sub-class of the abstract class " + + NonInterruptiveEvent.class.getTypeName() + "."); } nie = (NonInterruptiveEvent) eventClass.newInstance(); } catch (IllegalAccessException | InstantiationException e) { - throw new PhasedTestConfigurationException("We have had a problem instantiating the event "+in_event+".", e); + throw new PhasedTestConfigurationException( + "We have had a problem instantiating the event " + in_event + ".", e); } catch (ClassNotFoundException e) { - throw new PhasedTestConfigurationException("The given event class "+in_event+" could not be found.", e); + throw new PhasedTestConfigurationException("The given event class " + in_event + " could not be found.", e); } return nie; } @@ -158,15 +193,16 @@ protected static NonInterruptiveEvent finishEvent(String in_event, String in_onA log.info("Finishing event {} for step {}.", in_event, in_onAccountOfStep); NonInterruptiveEvent l_activeEvent = events.get(in_onAccountOfStep); if (l_activeEvent == null) { - throw new PhasedTestException("No event of the type "+in_event+" was stored for the test step "+in_onAccountOfStep); + throw new PhasedTestException( + "No event of the type " + in_event + " was stored for the test step " + in_onAccountOfStep); } try { if (Class.forName(in_event) != l_activeEvent.getClass()) { - throw new PhasedTestException("The given class "+in_event+" does not exist."); + throw new PhasedTestException("The given class " + in_event + " does not exist."); } } catch (ClassNotFoundException e) { - throw new PhasedTestConfigurationException("Class "+in_event+" not found.",e); + throw new PhasedTestConfigurationException("Class " + in_event + " not found.", e); } l_activeEvent.waitTillFinished(); @@ -194,6 +230,7 @@ public static Map getEvents() { /** * Extracts the event for a given method. The choice of the event is based on where the event is declared. + * * @param in_testResult A result object for a test containing the annotation {@link PhaseEvent} * @return An event that can be executed with this method. Null if no event is applicable */ @@ -218,9 +255,10 @@ public static String fetchEvent(ITestResult in_testResult) { int l_currentShuffleGroupNr = PhasedTestManager.asynchronousExtractIndex(in_testResult); - int l_currentStep = PhasedTestManager.getMethodMap().get(ClassPathParser.fetchFullName(l_currentMethod)).methodOrderInExecution; + int l_currentStep = PhasedTestManager.getMethodMap() + .get(ClassPathParser.fetchFullName(l_currentMethod)).methodOrderInExecution; - if (l_currentStep == l_currentShuffleGroupNr) { + if (l_currentStep == l_currentShuffleGroupNr) { return fetchApplicableEvent(l_currentMethod); } return null; @@ -232,9 +270,11 @@ public static ExecutorService getEventExecutor() { } public static void stopEventExecutor() { - if (eventExecutor != null) + if (eventExecutor != null) { eventExecutor.shutdown(); + } } + protected static enum EventMode {START, END} } diff --git a/src/main/java/com/adobe/campaign/tests/integro/phased/PhasedTestManager.java b/src/main/java/com/adobe/campaign/tests/integro/phased/PhasedTestManager.java index 5d7779c5..3d30caa7 100644 --- a/src/main/java/com/adobe/campaign/tests/integro/phased/PhasedTestManager.java +++ b/src/main/java/com/adobe/campaign/tests/integro/phased/PhasedTestManager.java @@ -553,7 +553,10 @@ public static Object[][] fetchProvidersShuffled(Method in_method, Phases in_phas + "_" + lt_nrAfterPhase; } else { - l_objectArrayPhased[rows][0] = STD_PHASED_GROUP_NIE_PREFIX + (rows+1); + Class l_event = PhasedEventManager.fetchApplicableEvent( + in_method.getDeclaringClass()); + + l_objectArrayPhased[rows][0] = STD_PHASED_GROUP_NIE_PREFIX + (l_event != null ? l_event.getSimpleName()+"_" : "" ) + (rows+1); } } @@ -593,7 +596,11 @@ public static Object[] fetchProvidersSingle(Method in_method) { } if (Phases.ASYNCHRONOUS.isSelected()) { - return new Object[] { STD_PHASED_GROUP_SINGLE }; + Class l_event = PhasedEventManager.fetchApplicableEvent( + in_method.getDeclaringClass()); + + return new Object[] { l_event == null ? STD_PHASED_GROUP_SINGLE : + PhasedTestManager.STD_PHASED_GROUP_NIE_PREFIX + l_event.getSimpleName() }; } return new Object[] {}; diff --git a/src/test/java/com/adobe/campaign/tests/integro/phased/PhasedTestManagerTests.java b/src/test/java/com/adobe/campaign/tests/integro/phased/PhasedTestManagerTests.java index 09fe7f6c..2247d08d 100644 --- a/src/test/java/com/adobe/campaign/tests/integro/phased/PhasedTestManagerTests.java +++ b/src/test/java/com/adobe/campaign/tests/integro/phased/PhasedTestManagerTests.java @@ -14,10 +14,7 @@ import com.adobe.campaign.tests.integro.phased.data.*; import com.adobe.campaign.tests.integro.phased.data.befaft.PhasedSeries_M_SimpleClass; import com.adobe.campaign.tests.integro.phased.data.dp.*; -import com.adobe.campaign.tests.integro.phased.data.events.NI_Event1; -import com.adobe.campaign.tests.integro.phased.data.events.TestSINGLEWithEvent_eventAsAnnotation; -import com.adobe.campaign.tests.integro.phased.data.events.TestSINGLEWithEvent_eventAsExecProperty; -import com.adobe.campaign.tests.integro.phased.data.events.TestShuffled_eventPassedAsExecutionVariable; +import com.adobe.campaign.tests.integro.phased.data.events.*; import com.adobe.campaign.tests.integro.phased.exceptions.PhasedTestConfigurationException; import com.adobe.campaign.tests.integro.phased.exceptions.PhasedTestException; import com.adobe.campaign.tests.integro.phased.utils.ClassPathParser; @@ -275,7 +272,7 @@ public void exportingDataTwice() throws IOException { } /** - * Testing {@code PROP_PHASED_DATA_PATH} that when the property {@value ConfigValueHandlerPhased#PROP_PHASED_DATA_PATH.systemName} is set, that path is + * Testing {@code PROP_PHASED_DATA_PATH} that when the property is set, that path is * used. * * Author : gandomi @@ -918,6 +915,65 @@ public void testCreateDataProviderData_forNonInterruptive() throws NoSuchMethodE } + @Test + public void testCreateDataProviderData_forNonInterruptiveWithEvent() throws NoSuchMethodException { + Phases.ASYNCHRONOUS.activate(); + + var eventClass = MyNonInterruptiveEvent.class; + ConfigValueHandlerPhased.EVENTS_NONINTERRUPTIVE.activate(eventClass.getTypeName()); + + Map, List> l_myMap = new HashMap<>(); + + Method method1 = PhasedSeries_F_Shuffle.class.getMethod("step1", String.class); + Method method2 = PhasedSeries_F_Shuffle.class.getMethod("step2", String.class); + Method method3 = PhasedSeries_F_Shuffle.class.getMethod("step3", String.class); + + l_myMap.put(PhasedSeries_F_Shuffle.class, + Arrays.asList(ClassPathParser.fetchFullName(method1), ClassPathParser.fetchFullName(method2), + ClassPathParser.fetchFullName(method3))); + + Map l_result = PhasedTestManager.generatePhasedProviders(l_myMap, + Phases.getCurrentPhase()); + + assertThat("we need to have the expected key", l_result.containsKey(ClassPathParser.fetchFullName(method1))); + assertThat("The first method should have three entries", l_result.get(ClassPathParser.fetchFullName(method1)).nrOfProviders, equalTo(3)); + + assertThat("The first method should have two entries", l_result.get(ClassPathParser.fetchFullName(method2)).nrOfProviders, equalTo(3)); + + assertThat("The first method should have one entry", l_result.get(ClassPathParser.fetchFullName(method3)).nrOfProviders, equalTo(3)); + + assertThat("We should have the same amount of total sizes", l_result.get(ClassPathParser.fetchFullName(method1)).totalClassMethods, + equalTo(l_result.get(ClassPathParser.fetchFullName(method2)).totalClassMethods)); + assertThat("We should have the same amount of total sizes", l_result.get(ClassPathParser.fetchFullName(method1)).totalClassMethods, + equalTo(l_result.get(ClassPathParser.fetchFullName(method3)).totalClassMethods)); + + Object[][] l_providerA = PhasedTestManager.fetchProvidersShuffled(method1); + + assertThat(l_providerA[0].length, equalTo(1)); + + var expectedPrefix = PhasedTestManager.STD_PHASED_GROUP_NIE_PREFIX +eventClass.getSimpleName(); + assertThat(l_providerA[0][0], equalTo(expectedPrefix+ "_1")); + assertThat(l_providerA[1][0], equalTo(expectedPrefix+ "_2")); + assertThat(l_providerA[2][0], equalTo(expectedPrefix + "_3")); + + Object[][] l_providerB = PhasedTestManager.fetchProvidersShuffled(method2); + + assertThat(l_providerB[0].length, equalTo(1)); + + assertThat(l_providerB[0][0], equalTo(expectedPrefix + "_1")); + assertThat(l_providerB[1][0], equalTo(expectedPrefix + "_2")); + assertThat(l_providerB[2][0], equalTo(expectedPrefix + "_3")); + + Object[][] l_providerC = PhasedTestManager.fetchProvidersShuffled(method3); + + assertThat(l_providerC[0].length, equalTo(1)); + + assertThat(l_providerC[0][0], equalTo(expectedPrefix + "_1")); + assertThat(l_providerC[1][0], equalTo(expectedPrefix + "_2")); + assertThat(l_providerC[2][0], equalTo(expectedPrefix + "_3")); + + } + @Test public void testPhasedManagerContext() { @@ -1136,11 +1192,10 @@ public void testFetchProvidersSingle_Consumer_InactiveNoExec() //NIE @Test - public void testFetchProvidersSingle_asynchronousNonInterruptive() + public void testFetchProvidersSingle_NIE_eventDefined() throws NoSuchMethodException, SecurityException { Phases.ASYNCHRONOUS.activate(); - //ConfigValueHandlerPhased.EVENTS_NONINTERRUPTIVE.activate(NI_Event1.class.getTypeName()); final Method l_myMethod1 = TestSINGLEWithEvent_eventAsAnnotation.class.getMethod("step1", String.class); final Method l_myMethod2 = TestSINGLEWithEvent_eventAsAnnotation.class.getMethod("step2", String.class); final Method l_myMethod3 = TestSINGLEWithEvent_eventAsAnnotation.class.getMethod("step3", String.class); @@ -1148,16 +1203,50 @@ public void testFetchProvidersSingle_asynchronousNonInterruptive() Object[] l_providerStep1 = PhasedTestManager.fetchProvidersSingle(l_myMethod1); assertThat("We should have a parameter for this method",l_providerStep1.length, equalTo(1)); - //System.out.println(PhasedEventManager.fetchEvent()); - assertThat("We should have the correct parameter for this method",l_providerStep1[0], equalTo(PhasedTestManager.STD_PHASED_GROUP_SINGLE)); + //System.out.println(PhasedEventManager.fetchEvent(l_myMethod1)); + var l_expectedGroup = PhasedTestManager.STD_PHASED_GROUP_NIE_PREFIX + "MyNonInterruptiveEvent"; + assertThat("We should have the correct parameter for this method",l_providerStep1[0], equalTo(l_expectedGroup)); + + Object[] l_providerStep2 = PhasedTestManager.fetchProvidersSingle(l_myMethod2); + + assertThat("We should have a parameter for this method",l_providerStep2.length, equalTo(1)); + assertThat("We should have the correct parameter for this method",l_providerStep2[0], equalTo(l_expectedGroup)); + + + Object[] l_providerStep3 = PhasedTestManager.fetchProvidersSingle(l_myMethod3); + + assertThat("We should have a parameter for this method",l_providerStep3.length, equalTo(1)); + assertThat("We should have the correct parameter for this method",l_providerStep3[0], equalTo(l_expectedGroup)); + } + + + @Test + public void testFetchProvidersSingle_NIE_eventSet() + throws NoSuchMethodException, SecurityException { + + Phases.ASYNCHRONOUS.activate(); + ConfigValueHandlerPhased.EVENTS_NONINTERRUPTIVE.activate(NI_Event2.class.getTypeName()); + final Method l_myMethod1 = TestShuffled_eventPassedAsExecutionVariable.class.getMethod("step1", String.class); + final Method l_myMethod2 = TestShuffled_eventPassedAsExecutionVariable.class.getMethod("step2", String.class); + final Method l_myMethod3 = TestShuffled_eventPassedAsExecutionVariable.class.getMethod("step3", String.class); + + Object[] l_providerStep1 = PhasedTestManager.fetchProvidersSingle(l_myMethod1); + var l_expectedGroup = PhasedTestManager.STD_PHASED_GROUP_NIE_PREFIX + "NI_Event2"; + + assertThat("We should have a parameter for this method",l_providerStep1.length, equalTo(1)); + + assertThat("We should have the correct parameter for this method",l_providerStep1[0], equalTo(l_expectedGroup)); Object[] l_providerStep2 = PhasedTestManager.fetchProvidersSingle(l_myMethod2); assertThat("We should have a parameter for this method",l_providerStep2.length, equalTo(1)); + assertThat("We should have the correct parameter for this method",l_providerStep2[0], equalTo(l_expectedGroup)); + Object[] l_providerStep3 = PhasedTestManager.fetchProvidersSingle(l_myMethod3); assertThat("We should have a parameter for this method",l_providerStep3.length, equalTo(1)); + assertThat("We should have the correct parameter for this method",l_providerStep3[0], equalTo(l_expectedGroup)); } diff --git a/src/test/java/com/adobe/campaign/tests/integro/phased/TestPhasedNonInterruptive.java b/src/test/java/com/adobe/campaign/tests/integro/phased/TestPhasedNonInterruptive.java index 74e950e5..12ff52ff 100644 --- a/src/test/java/com/adobe/campaign/tests/integro/phased/TestPhasedNonInterruptive.java +++ b/src/test/java/com/adobe/campaign/tests/integro/phased/TestPhasedNonInterruptive.java @@ -11,14 +11,21 @@ */ package com.adobe.campaign.tests.integro.phased; +import com.adobe.campaign.tests.integro.phased.data.NormalSeries_A; import com.adobe.campaign.tests.integro.phased.data.PhasedSeries_F_Shuffle; import com.adobe.campaign.tests.integro.phased.data.PhasedTestShuffledWithoutCanShuffleNested; import com.adobe.campaign.tests.integro.phased.data.events.*; import com.adobe.campaign.tests.integro.phased.exceptions.PhasedTestConfigurationException; import com.adobe.campaign.tests.integro.phased.exceptions.PhasedTestException; -import com.adobe.campaign.tests.integro.phased.utils.*; +import com.adobe.campaign.tests.integro.phased.utils.ClassPathParser; +import com.adobe.campaign.tests.integro.phased.utils.GeneralTestUtils; +import com.adobe.campaign.tests.integro.phased.utils.MockTestTools; +import com.adobe.campaign.tests.integro.phased.utils.TestTools; import org.hamcrest.Matchers; -import org.testng.*; +import org.testng.Assert; +import org.testng.ITestResult; +import org.testng.TestListenerAdapter; +import org.testng.TestNG; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -28,7 +35,10 @@ import java.io.File; import java.lang.reflect.Method; -import java.util.*; +import java.util.Arrays; +import java.util.Collections; +import java.util.Date; +import java.util.LinkedHashSet; import java.util.stream.Collectors; import static org.hamcrest.MatcherAssert.assertThat; @@ -51,7 +61,6 @@ public void resetVariables() { PhasedTestManager.MergedReportData.resetReport(); - //Delete standard cache file File l_importCacheFile = new File( GeneralTestUtils.fetchCacheDirectory(PhasedTestManager.STD_STORE_DIR), @@ -125,7 +134,7 @@ public void testNonInterruptiveEventHelloWorld_asString() @Test public void eventManagerTests() { String myEvent = MyNonInterruptiveEvent.class.getTypeName(); - assertThat("In the beginning executor should be null", PhasedEventManager.getEventExecutor(),nullValue()); + assertThat("In the beginning executor should be null", PhasedEventManager.getEventExecutor(), nullValue()); NonInterruptiveEvent nie = PhasedEventManager.startEvent(myEvent, "B"); Date start = new Date(); @@ -134,11 +143,9 @@ public void eventManagerTests() { assertThat("We should have stored an event object", PhasedEventManager.getEvents().get("B"), notNullValue()); assertThat("We should have stored our event object", PhasedEventManager.getEvents().get("B"), equalTo(nie)); - assertThat("There should be an event logged which is between the current and after dates", PhasedEventManager.getEventLogs().size(), equalTo(1)); - assertThat("The event should be currently on-going", !nie.isFinished()); //Stop event @@ -153,12 +160,12 @@ public void eventManagerTests() { assertThat("The duration should be less than 2 seconds", (finish.getTime() - start.getTime()), lessThan(600l)); assertThat("Our event should be finished", nie.getState().equals(NonInterruptiveEvent.states.FINISHED)); - assertThat("In the end executor should no longer be null (lazily instantiated)", PhasedEventManager.getEventExecutor(),notNullValue()); + assertThat("In the end executor should no longer be null (lazily instantiated)", + PhasedEventManager.getEventExecutor(), notNullValue()); //PhasedEventManager.stopEventManager(); } - @Test public void eventManagerTests_conclusive() { String myEvent = MyNonInterruptiveClosureEvent.class.getTypeName(); @@ -170,11 +177,9 @@ public void eventManagerTests_conclusive() { assertThat("We should have stored an event object", PhasedEventManager.getEvents().get("B"), notNullValue()); assertThat("We should have stored our event object", PhasedEventManager.getEvents().get("B"), equalTo(nie)); - assertThat("There should be an event logged which is between the current and after dates", PhasedEventManager.getEventLogs().size(), equalTo(1)); - assertThat("The event should be currently on-going", !nie.isFinished()); //Stop event @@ -190,8 +195,9 @@ public void eventManagerTests_conclusive() { System.out.println("Marker for eventManagerTests_conclusive"); assertThat("Our event should be finished", nie.getState().equals(NonInterruptiveEvent.states.FINISHED)); - assertThat("In the end executor should no longer be null (lazily instantiated)", PhasedEventManager.getEventExecutor(),notNullValue()); - assertThat(((MyNonInterruptiveClosureEvent)nieEND).getTaskContainer(),equalTo(-2)); + assertThat("In the end executor should no longer be null (lazily instantiated)", + PhasedEventManager.getEventExecutor(), notNullValue()); + assertThat(((MyNonInterruptiveClosureEvent) nieEND).getTaskContainer(), equalTo(-2)); //PhasedEventManager.stopEventManager(); } @@ -232,7 +238,7 @@ public void eventManagerTestsEnd_negativeBadEvent() { assertThrows(PhasedTestException.class, () -> PhasedEventManager.finishEvent(NI_Event2.class.getTypeName(), l_stepName)); - PhasedEventManager.events.put(l_stepName,new MyNonInterruptiveEvent()); + PhasedEventManager.events.put(l_stepName, new MyNonInterruptiveEvent()); assertThrows(PhasedTestConfigurationException.class, () -> PhasedEventManager.finishEvent("NonExistantClass", l_stepName)); } @@ -241,15 +247,16 @@ public void eventManagerTestsEnd_negativeBadEvent() { public void testExtractEvent_SINGLE() throws NoSuchMethodException { //Case 1 Event Declared on PhasedEvent annotation Method l_methodWithEvent = TestSINGLEWithEvent_eventAsAnnotation.class.getMethod("step2", String.class); - ITestResult l_itr1 = MockTestTools.generateTestResultMock(l_methodWithEvent, new Object[]{"D"}); + ITestResult l_itr1 = MockTestTools.generateTestResultMock(l_methodWithEvent, new Object[] { "D" }); assertThat("We should correctly extract the event from the method", - PhasedEventManager.fetchApplicableEvent(l_methodWithEvent), equalTo(MyNonInterruptiveEvent.class.getTypeName())); + PhasedEventManager.fetchApplicableEvent(l_methodWithEvent), + equalTo(MyNonInterruptiveEvent.class.getTypeName())); //Case 2 Event Declared as Exec property Method l_methodWithNoEventSet = TestSINGLEWithEvent_eventAsExecProperty.class.getMethod("step2", String.class); - ITestResult l_itr2 = MockTestTools.generateTestResultMock(l_methodWithNoEventSet, new Object[]{"D"}); + ITestResult l_itr2 = MockTestTools.generateTestResultMock(l_methodWithNoEventSet, new Object[] { "D" }); assertThat("We should have no event set for this method at this stage", PhasedEventManager.fetchApplicableEvent(l_methodWithNoEventSet), nullValue()); @@ -259,15 +266,19 @@ public void testExtractEvent_SINGLE() throws NoSuchMethodException { equalTo(MyNonInterruptiveEvent2.class.getTypeName())); assertThat("We should correctly extract the event from the method", - PhasedEventManager.fetchApplicableEvent(l_methodWithNoEventSet), equalTo(MyNonInterruptiveEvent2.class.getTypeName())); + PhasedEventManager.fetchApplicableEvent(l_methodWithNoEventSet), + equalTo(MyNonInterruptiveEvent2.class.getTypeName())); //Case 3 Event Declared on PhasedTest ConfigValueHandlerPhased.EVENTS_NONINTERRUPTIVE.reset(); - Method l_methodWithEventDefinedOnPhasedTest = TestSINGLEWithEvent_eventConfiguredOnPhasedTestAnnotation.class.getMethod("step2", String.class); - ITestResult l_itr3 = MockTestTools.generateTestResultMock(l_methodWithEventDefinedOnPhasedTest, new Object[]{"D"}); + Method l_methodWithEventDefinedOnPhasedTest = TestSINGLEWithEvent_eventConfiguredOnPhasedTestAnnotation.class.getMethod( + "step2", String.class); + ITestResult l_itr3 = MockTestTools.generateTestResultMock(l_methodWithEventDefinedOnPhasedTest, + new Object[] { "D" }); assertThat("We should correctly extract the event from the Phased Test annotation", - PhasedEventManager.fetchApplicableEvent(l_methodWithEventDefinedOnPhasedTest), equalTo(MyNonInterruptiveEvent.class.getTypeName())); + PhasedEventManager.fetchApplicableEvent(l_methodWithEventDefinedOnPhasedTest), + equalTo(MyNonInterruptiveEvent.class.getTypeName())); assertThat("We should correctly extract the event from the method", PhasedEventManager.fetchEvent(l_itr3), @@ -275,37 +286,43 @@ public void testExtractEvent_SINGLE() throws NoSuchMethodException { } - @Test(description = "Testing that events respect the set precedence order") public void testExtractEvent_SINGLE_precendenceTests() throws NoSuchMethodException { //Case 1 Event declared on PhasedEvent and on Exec Property Method l_methodWithEvent = TestSINGLEWithEvent_eventAsAnnotation.class.getMethod("step2", String.class); - ITestResult l_itr1 = MockTestTools.generateTestResultMock(l_methodWithEvent, new Object[]{"D"}); + ITestResult l_itr1 = MockTestTools.generateTestResultMock(l_methodWithEvent, new Object[] { "D" }); assertThat("We should correctly extract the event from the method", - PhasedEventManager.fetchApplicableEvent(l_methodWithEvent), equalTo(MyNonInterruptiveEvent.class.getTypeName())); + PhasedEventManager.fetchApplicableEvent(l_methodWithEvent), + equalTo(MyNonInterruptiveEvent.class.getTypeName())); ConfigValueHandlerPhased.EVENTS_NONINTERRUPTIVE.activate(MyNonInterruptiveEvent2.class.getTypeName()); assertThat("The Event annotation should have presedence here", - PhasedEventManager.fetchApplicableEvent(l_methodWithEvent), equalTo(MyNonInterruptiveEvent.class.getTypeName())); + PhasedEventManager.fetchApplicableEvent(l_methodWithEvent), + equalTo(MyNonInterruptiveEvent.class.getTypeName())); //Case 2 Event declared on PhasedEvent and on PhasedTest - Method l_methodWithEventOnBothPhasedEventAndPhasedTest = TestSINGLEWithEvent_eventAsAnnotationOnTwoLevels.class.getMethod("step2", String.class); - ITestResult l_itr2 = MockTestTools.generateTestResultMock(l_methodWithEventOnBothPhasedEventAndPhasedTest, new Object[]{"D"}); + Method l_methodWithEventOnBothPhasedEventAndPhasedTest = TestSINGLEWithEvent_eventAsAnnotationOnTwoLevels.class.getMethod( + "step2", String.class); + ITestResult l_itr2 = MockTestTools.generateTestResultMock(l_methodWithEventOnBothPhasedEventAndPhasedTest, + new Object[] { "D" }); assertThat("We should correctly extract the event from the method", PhasedEventManager.fetchEvent(l_itr2), equalTo(MyNonInterruptiveEvent.class.getTypeName())); //Case 3 - Method l_methodWithEventDefinedOnPhasedTest = TestSINGLEWithEvent_eventConfiguredOnPhasedTestAnnotation.class.getMethod("step2", String.class); - ITestResult l_itr3 = MockTestTools.generateTestResultMock(l_methodWithEventDefinedOnPhasedTest, new Object[]{"D"}); + Method l_methodWithEventDefinedOnPhasedTest = TestSINGLEWithEvent_eventConfiguredOnPhasedTestAnnotation.class.getMethod( + "step2", String.class); + ITestResult l_itr3 = MockTestTools.generateTestResultMock(l_methodWithEventDefinedOnPhasedTest, + new Object[] { "D" }); ConfigValueHandlerPhased.EVENTS_NONINTERRUPTIVE.activate(MyNonInterruptiveEvent2.class.getTypeName()); assertThat("We should correctly extract the event from the Phased Test annotation", - PhasedEventManager.fetchApplicableEvent(l_methodWithEventDefinedOnPhasedTest), equalTo(MyNonInterruptiveEvent.class.getTypeName())); + PhasedEventManager.fetchApplicableEvent(l_methodWithEventDefinedOnPhasedTest), + equalTo(MyNonInterruptiveEvent.class.getTypeName())); assertThat("We should correctly extract the event from the method", PhasedEventManager.fetchEvent(l_itr3), @@ -330,11 +347,12 @@ public void testExtractEvent_SINGLE_Negative() throws NoSuchMethodException { public void testExtractEvent_SUFFLED() throws NoSuchMethodException { Method l_methodWithEvent = TestShuffled_eventPassedAsExecutionVariable.class.getMethod("step1", String.class); String l_phaseGroup = PhasedTestManager.STD_PHASED_GROUP_NIE_PREFIX + "1"; - ITestResult l_itr1 = MockTestTools.generateTestResultMock(l_methodWithEvent, new Object[]{ l_phaseGroup }); + ITestResult l_itr1 = MockTestTools.generateTestResultMock(l_methodWithEvent, new Object[] { l_phaseGroup }); ConfigValueHandlerPhased.EVENTS_NONINTERRUPTIVE.activate(MyNonInterruptiveEvent.class.getTypeName()); - PhasedTestManager.getMethodMap().put(ClassPathParser.fetchFullName(l_methodWithEvent), new MethodMapping(TestShuffled_eventPassedAsExecutionVariable.class, 3, 3, 1)); + PhasedTestManager.getMethodMap().put(ClassPathParser.fetchFullName(l_methodWithEvent), + new MethodMapping(TestShuffled_eventPassedAsExecutionVariable.class, 3, 3, 1)); assertThat("We should correctly extract the event from the method", PhasedEventManager.fetchEvent(l_itr1), @@ -350,9 +368,10 @@ public void testExtractEvent_SUFFLED() throws NoSuchMethodException { @Test(description = "Testing the hierarchy of the event definitions on the shuffled mode") public void testExtractEvent_SUFFLED_definitionOnAnnotation() throws NoSuchMethodException { - Method l_methodWithEvent = TestShuffled_eventDefinedOnPhasedTestAnnotation.class.getMethod("step2", String.class); + Method l_methodWithEvent = TestShuffled_eventDefinedOnPhasedTestAnnotation.class.getMethod("step2", + String.class); String l_phaseGroup = PhasedTestManager.STD_PHASED_GROUP_NIE_PREFIX + "1"; - ITestResult l_itr1 = MockTestTools.generateTestResultMock(l_methodWithEvent, new Object[]{ l_phaseGroup }); + ITestResult l_itr1 = MockTestTools.generateTestResultMock(l_methodWithEvent, new Object[] { l_phaseGroup }); assertThat("We should correctly extract the event from the method", PhasedEventManager.fetchApplicableEvent(l_methodWithEvent), @@ -364,7 +383,8 @@ public void testExtractEvent_SUFFLED_definitionOnAnnotation() throws NoSuchMetho PhasedEventManager.fetchApplicableEvent(l_methodWithEvent), equalTo(MyNonInterruptiveEvent.class.getTypeName())); - PhasedTestManager.getMethodMap().put(ClassPathParser.fetchFullName(l_methodWithEvent), new MethodMapping(TestShuffled_eventDefinedOnPhasedTestAnnotation.class, 3, 3, 1)); + PhasedTestManager.getMethodMap().put(ClassPathParser.fetchFullName(l_methodWithEvent), + new MethodMapping(TestShuffled_eventDefinedOnPhasedTestAnnotation.class, 3, 3, 1)); assertThat("We should correctly extract the event from the method", PhasedEventManager.fetchEvent(l_itr1), @@ -388,7 +408,6 @@ public void testExtractEventForTargettedEvent() throws NoSuchMethodException { Matchers.nullValue()); } - @Test public void testFetchEventInformation() throws NoSuchMethodException { final Class l_testClass = TestSINGLEWithEvent_eventAsAnnotation.class; @@ -406,7 +425,7 @@ public void testFetchEventInformation() throws NoSuchMethodException { * In this example we pass an event as a system property. The class has an event */ @Test - public void testNonInterruptive_ParellelHardCoded_SINGLE() { + public void testNonInterruptive_ParellelHardCoded_SINGLE() { // Rampup TestNG myTestNG = TestTools.createTestNG(); TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); @@ -447,9 +466,12 @@ public void testNonInterruptive_ParellelHardCoded_SINGLE() { assertThat("The first element should be an event defined in step2", l_eventStartLog.getEventName(), Matchers.equalTo(MyNonInterruptiveEvent.class.getTypeName())); + + var l_shaffleGroup = PhasedTestManager.STD_PHASED_GROUP_NIE_PREFIX+MyNonInterruptiveEvent.class.getSimpleName(); + assertThat("The first element should be an event started by step2", l_eventStartLog.getPhasedStepName(), Matchers.equalTo( - "com.adobe.campaign.tests.integro.phased.data.events.TestSINGLEWithEvent_eventAsAnnotation.step2(phased-singleRun)")); + "com.adobe.campaign.tests.integro.phased.data.events.TestSINGLEWithEvent_eventAsAnnotation.step2("+l_shaffleGroup+")")); ITestResult l_testSubjectedToEvent = tla.getPassedTests().stream().filter(t -> t.getName().equals("step2")) .collect(Collectors.toList()).get(0); @@ -464,7 +486,7 @@ public void testNonInterruptive_ParellelHardCoded_SINGLE() { Matchers.equalTo(MyNonInterruptiveEvent.class.getTypeName())); assertThat("The second element should be an event started by step2", l_eventEndLog.getPhasedStepName(), Matchers.equalTo( - "com.adobe.campaign.tests.integro.phased.data.events.TestSINGLEWithEvent_eventAsAnnotation.step2(phased-singleRun)")); + "com.adobe.campaign.tests.integro.phased.data.events.TestSINGLEWithEvent_eventAsAnnotation.step2("+l_shaffleGroup+")")); assertThat("Our test should have started before the end of the event", l_testSubjectedToEvent.getStartMillis(), lessThan(l_eventEndLog.getEventDate().getTime())); @@ -473,10 +495,9 @@ public void testNonInterruptive_ParellelHardCoded_SINGLE() { /** * In this example we pass an event as a system property. The class has an event - * */ @Test - public void testNonInterruptive_ParellelConfigured_SINGLELegacy() { + public void testNonInterruptive_ParellelConfigured_SINGLELegacy() { // Rampup TestNG myTestNG = TestTools.createTestNG(); TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); @@ -518,9 +539,12 @@ public void testNonInterruptive_ParellelConfigured_SINGLELegacy() { assertThat("The first element should be an event defined in step2", l_eventStartLog.getEventName(), Matchers.equalTo(MyNonInterruptiveEvent.class.getTypeName())); + + var l_shaffleGroup = PhasedTestManager.STD_PHASED_GROUP_NIE_PREFIX+MyNonInterruptiveEvent.class.getSimpleName(); + assertThat("The first element should be an event started by step2", l_eventStartLog.getPhasedStepName(), Matchers.equalTo( - l_testClass.getTypeName() + ".step2(phased-singleRun)")); + l_testClass.getTypeName() + ".step2("+l_shaffleGroup+")")); ITestResult l_testSubjectedToEvent = tla.getPassedTests().stream().filter(t -> t.getName().equals("step2")) .collect(Collectors.toList()).get(0); @@ -535,20 +559,18 @@ public void testNonInterruptive_ParellelConfigured_SINGLELegacy() { Matchers.equalTo(MyNonInterruptiveEvent.class.getTypeName())); assertThat("The second element should be an event started by step2", l_eventEndLog.getPhasedStepName(), Matchers.equalTo( - l_testClass.getTypeName() + ".step2(phased-singleRun)")); + l_testClass.getTypeName() + ".step2("+l_shaffleGroup+")")); assertThat("Our test should have started before the end of the event", l_testSubjectedToEvent.getStartMillis(), lessThan(l_eventEndLog.getEventDate().getTime())); } - /** * In this example we pass an event as a system property. The class has an event - * */ @Test - public void testNonInterruptive_ParellelConfigured_SINGLE() { + public void testNonInterruptive_ParellelConfigured_SINGLE() { // Rampup TestNG myTestNG = TestTools.createTestNG(); TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); @@ -590,9 +612,10 @@ public void testNonInterruptive_ParellelConfigured_SINGLE() { assertThat("The first element should be an event defined in step2", l_eventStartLog.getEventName(), Matchers.equalTo(MyNonInterruptiveEvent.class.getTypeName())); + var l_shaffleGroup = PhasedTestManager.STD_PHASED_GROUP_NIE_PREFIX+MyNonInterruptiveEvent.class.getSimpleName(); assertThat("The first element should be an event started by step2", l_eventStartLog.getPhasedStepName(), Matchers.equalTo( - l_testClass.getTypeName() + ".step2(phased-singleRun)")); + l_testClass.getTypeName() + ".step2(" + l_shaffleGroup + ")")); ITestResult l_testSubjectedToEvent = tla.getPassedTests().stream().filter(t -> t.getName().equals("step2")) .collect(Collectors.toList()).get(0); @@ -607,7 +630,7 @@ public void testNonInterruptive_ParellelConfigured_SINGLE() { Matchers.equalTo(MyNonInterruptiveEvent.class.getTypeName())); assertThat("The second element should be an event started by step2", l_eventEndLog.getPhasedStepName(), Matchers.equalTo( - l_testClass.getTypeName() + ".step2(phased-singleRun)")); + l_testClass.getTypeName() + ".step2(" + l_shaffleGroup + ")")); assertThat("Our test should have started before the end of the event", l_testSubjectedToEvent.getStartMillis(), lessThan(l_eventEndLog.getEventDate().getTime())); @@ -641,7 +664,8 @@ public void testNonInterruptive_ParellelConfiguredAsExecutionVariable_ShuffledLe myTestNG.run(); - assertThat("We should be in non-interruptive mode shuffled", PhasedTestManager.isPhasedTestShuffledMode(l_testClass)); + assertThat("We should be in non-interruptive mode shuffled", + PhasedTestManager.isPhasedTestShuffledMode(l_testClass)); assertThat("We should have 9 successful methods of phased Tests", (int) tla.getPassedTests().stream().filter(m -> m.getInstance().getClass().equals(l_testClass)).count(), @@ -651,7 +675,8 @@ public void testNonInterruptive_ParellelConfiguredAsExecutionVariable_ShuffledLe assertThat("We should have no failed tests", tla.getFailedTests().size(), equalTo(0)); assertThat("We should have no skipped tests", tla.getSkippedTests().size(), equalTo(0)); - assertThat("We should have the correct number of events in the logs (1 x phase groups)", PhasedEventManager.getEventLogs().size(), + assertThat("We should have the correct number of events in the logs (1 x phase groups)", + PhasedEventManager.getEventLogs().size(), Matchers.equalTo(6)); } @@ -682,7 +707,8 @@ public void testNonInterruptive_ParellelConfiguredAsExecutionVariable_Shuffled() myTestNG.run(); - assertThat("We should be in non-interruptive mode shuffled", PhasedTestManager.isPhasedTestShuffledMode(l_testClass)); + assertThat("We should be in non-interruptive mode shuffled", + PhasedTestManager.isPhasedTestShuffledMode(l_testClass)); assertThat("We should have 9 successful methods of phased Tests", (int) tla.getPassedTests().stream().filter(m -> m.getInstance().getClass().equals(l_testClass)).count(), @@ -692,11 +718,11 @@ public void testNonInterruptive_ParellelConfiguredAsExecutionVariable_Shuffled() assertThat("We should have no failed tests", tla.getFailedTests().size(), equalTo(0)); assertThat("We should have no skipped tests", tla.getSkippedTests().size(), equalTo(0)); - assertThat("We should have the correct number of events in the logs (1 x phase groups)", PhasedEventManager.getEventLogs().size(), + assertThat("We should have the correct number of events in the logs (1 x phase groups)", + PhasedEventManager.getEventLogs().size(), Matchers.equalTo(6)); } - /** * This is a test for non-intyerruptive events in shuffled classes. Using the legacy annotations */ @@ -721,11 +747,14 @@ public void testNonInterruptive_ParellelConfiguredAsExecutionVariableTargetted_S Phases.ASYNCHRONOUS.activate(); ConfigValueHandlerPhased.EVENTS_NONINTERRUPTIVE.activate(MyNonInterruptiveEvent.class.getTypeName()); - ConfigValueHandlerPhased.EVENT_TARGET.activate(PhasedTestShuffledWithoutCanShuffleNested.PhasedTestShuffledWithoutCanShuffleNestedInner.class.getTypeName()+"#step3"); + ConfigValueHandlerPhased.EVENT_TARGET.activate( + PhasedTestShuffledWithoutCanShuffleNested.PhasedTestShuffledWithoutCanShuffleNestedInner.class.getTypeName() + + "#step3"); myTestNG.run(); - assertThat("We should be in non-interruptive mode shuffled", !PhasedTestManager.isPhasedTestShuffledMode(l_testClass)); + assertThat("We should be in non-interruptive mode shuffled", + !PhasedTestManager.isPhasedTestShuffledMode(l_testClass)); assertThat("We should have 3 successful methods of phased Tests", (int) tla.getPassedTests().stream().filter(m -> m.getInstance().getClass().equals(l_testClass)).count(), @@ -735,11 +764,11 @@ public void testNonInterruptive_ParellelConfiguredAsExecutionVariableTargetted_S assertThat("We should have no failed tests", tla.getFailedTests().size(), equalTo(0)); assertThat("We should have no skipped tests", tla.getSkippedTests().size(), equalTo(0)); - assertThat("We should have the correct number of events in the logs (1 x phase groups)", PhasedEventManager.getEventLogs().size(), + assertThat("We should have the correct number of events in the logs (1 x phase groups)", + PhasedEventManager.getEventLogs().size(), Matchers.equalTo(2)); } - /** * This is a test for non-intyerruptive events in shuffled classes */ @@ -768,7 +797,8 @@ public void testNonInterruptive_ParellelConfiguredAsExecutionVariable_Shuffled_O myTestNG.run(); - assertThat("We should be in non-interruptive mode shuffled", PhasedTestManager.isPhasedTestShuffledMode(l_testClass)); + assertThat("We should be in non-interruptive mode shuffled", + PhasedTestManager.isPhasedTestShuffledMode(l_testClass)); assertThat("We should have 9 successful methods of phased Tests", (int) tla.getPassedTests().stream().filter(m -> m.getInstance().getClass().equals(l_testClass)).count(), @@ -778,11 +808,11 @@ public void testNonInterruptive_ParellelConfiguredAsExecutionVariable_Shuffled_O assertThat("We should have no failed tests", tla.getFailedTests().size(), equalTo(0)); assertThat("We should have no skipped tests", tla.getSkippedTests().size(), equalTo(0)); - assertThat("We should have the correct number of events in the logs (1 x phase groups)", PhasedEventManager.getEventLogs().size(), + assertThat("We should have the correct number of events in the logs (1 x phase groups)", + PhasedEventManager.getEventLogs().size(), Matchers.equalTo(6)); } - @Test public void testNonInterruptive_ParellelConfigured_Shuffled_AfterPhase() { @@ -805,10 +835,12 @@ public void testNonInterruptive_ParellelConfigured_Shuffled_AfterPhase() { Phases.ASYNCHRONOUS.activate(); ConfigValueHandlerPhased.EVENTS_NONINTERRUPTIVE.activate(MyNonInterruptiveEvent.class.getTypeName()); - assertThat("The after phase should not yet have been updated", TestShuffled_eventConfiguredAfter.originalValue, Matchers.equalTo(0)); + assertThat("The after phase should not yet have been updated", TestShuffled_eventConfiguredAfter.originalValue, + Matchers.equalTo(0)); myTestNG.run(); - assertThat("We should be in non-interruptive mode shuffled", PhasedTestManager.isPhasedTestShuffledMode(l_testClass)); + assertThat("We should be in non-interruptive mode shuffled", + PhasedTestManager.isPhasedTestShuffledMode(l_testClass)); assertThat("We should have 9 successful methods of phased Tests", (int) tla.getPassedTests().stream().filter(m -> m.getInstance().getClass().equals(l_testClass)).count(), @@ -818,13 +850,14 @@ public void testNonInterruptive_ParellelConfigured_Shuffled_AfterPhase() { assertThat("We should have no failed tests", tla.getFailedTests().size(), equalTo(0)); assertThat("We should have no skipped tests", tla.getSkippedTests().size(), equalTo(0)); - assertThat("We should have the correct number of events in the logs (1 x phase groups)", PhasedEventManager.getEventLogs().size(), + assertThat("We should have the correct number of events in the logs (1 x phase groups)", + PhasedEventManager.getEventLogs().size(), Matchers.equalTo(6)); - assertThat("The after phase should not yet have been updated", TestShuffled_eventConfiguredAfter.originalValue, Matchers.equalTo(1)); + assertThat("The after phase should not yet have been updated", TestShuffled_eventConfiguredAfter.originalValue, + Matchers.equalTo(1)); } - /** * Testing that the event is declared on the phased annotation level */ @@ -851,7 +884,8 @@ public void testNonInterruptive_ParellelConfiguredOnPhaseTestAnnotation_Shuffled myTestNG.run(); - assertThat("We should be in non-interruptive mode shuffled", PhasedTestManager.isPhasedTestShuffledMode(l_testClass)); + assertThat("We should be in non-interruptive mode shuffled", + PhasedTestManager.isPhasedTestShuffledMode(l_testClass)); assertThat("We should have 9 successful methods of phased Tests", (int) tla.getPassedTests().stream().filter(m -> m.getInstance().getClass().equals(l_testClass)).count(), @@ -861,7 +895,80 @@ public void testNonInterruptive_ParellelConfiguredOnPhaseTestAnnotation_Shuffled assertThat("We should have no failed tests", tla.getFailedTests().size(), equalTo(0)); assertThat("We should have no skipped tests", tla.getSkippedTests().size(), equalTo(0)); - assertThat("We should have the correct number of events in the logs (1 x phase groups)", PhasedEventManager.getEventLogs().size(), + assertThat("We should have the correct number of events in the logs (1 x phase groups)", + PhasedEventManager.getEventLogs().size(), Matchers.equalTo(6)); } + + @Test + public void testEventAppliesTo_specificEventAnnotationOnMethod() throws NoSuchMethodException { + //Case 1 Event Declared on PhasedEvent annotation + Method l_methodWithEvent = TestSINGLEWithEvent_eventAsAnnotation.class.getMethod("step2", String.class); + + assertThat("We should correctly extract the event from the method", + PhasedEventManager.fetchApplicableEvent(l_methodWithEvent), + equalTo(MyNonInterruptiveEvent.class.getTypeName())); + + assertThat("We should correctly identify that this class could be subject to a non-interruptive event", + PhasedEventManager.fetchApplicableEvent(TestSINGLEWithEvent_eventAsAnnotation.class), + Matchers.equalTo(MyNonInterruptiveEvent.class)); + } + + @Test + public void testEventAppliesTo_eventAnnotationOnMethod() throws NoSuchMethodException { + //Case 2A Event Declared as Exec property with none set + assertThat("We should correctly extract the event from the method", + PhasedEventManager.fetchApplicableEvent(TestSINGLEWithEvent_eventAsExecProperty.class), nullValue()); + + ConfigValueHandlerPhased.EVENTS_NONINTERRUPTIVE.activate(MyNonInterruptiveEvent.class.getTypeName()); + + //Case 2B Event Declared as Exec property with none set + assertThat("We should correctly extract the event from the method", + PhasedEventManager.fetchApplicableEvent(TestSINGLEWithEvent_eventAsExecProperty.class), + Matchers.equalTo(MyNonInterruptiveEvent.class)); + } + + @Test + public void testEventAppliesTo_eventInjected() throws NoSuchMethodException { + + assertThat("By default this scenario is not subject to an event", + PhasedEventManager.fetchApplicableEvent(PhasedSeries_F_Shuffle.class), + Matchers.nullValue()); + + //Case 3 Normal test where the event is injected into the + Method l_targettedMethodWithoutEvent = PhasedSeries_F_Shuffle.class.getMethod("step2", String.class); + ConfigValueHandlerPhased.EVENTS_NONINTERRUPTIVE.activate(MyNonInterruptiveEvent.class.getTypeName()); + ConfigValueHandlerPhased.EVENT_TARGET.activate(ClassPathParser.fetchFullName(l_targettedMethodWithoutEvent)); + + assertThat("Now that one of the methods is targetted, we should correctly extract the event from the method", + PhasedEventManager.fetchApplicableEvent(TestSINGLEWithEvent_eventAsExecProperty.class), + Matchers.equalTo(MyNonInterruptiveEvent.class)); + + } + + + @Test + public void testEventAppliesTo_noEventAnnotationClass() throws NoSuchMethodException { + + //Case 2B Event Declared as Exec property with none set + assertThat("We should correctly extract the event from the method", + PhasedEventManager.fetchApplicableEvent(TestShuffled_eventDefinedOnPhasedTestAnnotation.class), + Matchers.equalTo(MyNonInterruptiveEvent.class)); + } + + @Test + public void testEventAppliesTo_NEGATIVE_nonExitingEvent() throws NoSuchMethodException { + ConfigValueHandlerPhased.EVENTS_NONINTERRUPTIVE.activate("i.really.do.not.Exist"); + Assert.assertThrows(PhasedTestConfigurationException.class, () -> + PhasedEventManager.fetchApplicableEvent(PhasedSeries_F_Shuffle.class)); + } + + @Test + public void testEventAppliesTo_NEGATIVE_eventNotAnEvent() throws NoSuchMethodException { + + assertThat("", NonInterruptiveEvent.class.isAssignableFrom(MyNonInterruptiveEvent.class)); + ConfigValueHandlerPhased.EVENTS_NONINTERRUPTIVE.activate(NormalSeries_A.class.getTypeName()); + Assert.assertThrows(PhasedTestConfigurationException.class, () -> + PhasedEventManager.fetchApplicableEvent(PhasedSeries_F_Shuffle.class)); + } } From 12a14fe3a1820b6af239b3a265bc1ec96121a234 Mon Sep 17 00:00:00 2001 From: baubakg Date: Fri, 27 Sep 2024 16:51:11 +0200 Subject: [PATCH 3/6] Updating the diagrams --- diagrams/PhasedDiagrams.drawio | 388 +-------------------------------- 1 file changed, 2 insertions(+), 386 deletions(-) diff --git a/diagrams/PhasedDiagrams.drawio b/diagrams/PhasedDiagrams.drawio index af0ac8ae..36da0ceb 100644 --- a/diagrams/PhasedDiagrams.drawio +++ b/diagrams/PhasedDiagrams.drawio @@ -1,4 +1,4 @@ - + @@ -1366,391 +1366,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + From 4d34f4f51563a9399a59ea465f140fd0b07bdace Mon Sep 17 00:00:00 2001 From: baubakg Date: Fri, 27 Sep 2024 17:04:57 +0200 Subject: [PATCH 4/6] renamed the phase group prefixes for the non-interruptive events --- .../adobe/campaign/tests/integro/phased/PhasedTestManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/adobe/campaign/tests/integro/phased/PhasedTestManager.java b/src/main/java/com/adobe/campaign/tests/integro/phased/PhasedTestManager.java index 3d30caa7..2da8c6db 100644 --- a/src/main/java/com/adobe/campaign/tests/integro/phased/PhasedTestManager.java +++ b/src/main/java/com/adobe/campaign/tests/integro/phased/PhasedTestManager.java @@ -54,7 +54,7 @@ private PhasedTestManager() { static final String STD_PHASED_GROUP_PREFIX = "phased-shuffledGroup_"; static final String STD_PHASED_GROUP_SINGLE = "phased-singleRun"; - static final String STD_PHASED_GROUP_NIE_PREFIX = "phased-shuffledGroupNIE_"; + static final String STD_PHASED_GROUP_NIE_PREFIX = "ni_event_"; public static final String STD_MERGE_STEP_ERROR_PREFIX = "Phased Error: Failure in step "; From d628a86a5a0a0e73cfb8819b5a1c418e9f08afc5 Mon Sep 17 00:00:00 2001 From: baubakg Date: Fri, 27 Sep 2024 17:15:21 +0200 Subject: [PATCH 5/6] Addressing sonar issue --- .../campaign/tests/integro/phased/PhasedEventManager.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/adobe/campaign/tests/integro/phased/PhasedEventManager.java b/src/main/java/com/adobe/campaign/tests/integro/phased/PhasedEventManager.java index ed8a704c..ed6335b6 100644 --- a/src/main/java/com/adobe/campaign/tests/integro/phased/PhasedEventManager.java +++ b/src/main/java/com/adobe/campaign/tests/integro/phased/PhasedEventManager.java @@ -151,22 +151,26 @@ protected static NonInterruptiveEvent startEvent(String in_event, String in_onAc logEvent(EventMode.START, in_event, in_onAccountOfStep); events.put(in_onAccountOfStep, nie); nie.threadFuture = eventExecutor.submit(nie); + + //Check that the vent really starts while (nie.getState().equals(NonInterruptiveEvent.states.DEFINED)) { try { //log.debug("Waiting for event to start"); Thread.sleep(1); } catch (InterruptedException e) { Thread.currentThread().interrupt(); - throw new RuntimeException(e); + throw new PhasedTestingEventException("Un expected exception at startup",e); } } + //Check if the event had no issues if (nie.getState().equals(NonInterruptiveEvent.states.FAILURE)) { log.error("Event Exception : The event {} for step {} caused an exception during start.", in_event, in_onAccountOfStep); try { nie.threadFuture.get(); } catch (InterruptedException | ExecutionException ex) { ex.getCause().printStackTrace(); + nie.threadFuture.cancel(true); } } From bf7c8ac7573070e64d15c8e42871dc34b79b17e4 Mon Sep 17 00:00:00 2001 From: baubakg Date: Fri, 27 Sep 2024 17:51:07 +0200 Subject: [PATCH 6/6] Fixed snar issue as they like it --- .../campaign/tests/integro/phased/PhasedEventManager.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/adobe/campaign/tests/integro/phased/PhasedEventManager.java b/src/main/java/com/adobe/campaign/tests/integro/phased/PhasedEventManager.java index ed6335b6..d12eb9ba 100644 --- a/src/main/java/com/adobe/campaign/tests/integro/phased/PhasedEventManager.java +++ b/src/main/java/com/adobe/campaign/tests/integro/phased/PhasedEventManager.java @@ -168,9 +168,11 @@ protected static NonInterruptiveEvent startEvent(String in_event, String in_onAc log.error("Event Exception : The event {} for step {} caused an exception during start.", in_event, in_onAccountOfStep); try { nie.threadFuture.get(); - } catch (InterruptedException | ExecutionException ex) { + } catch (ExecutionException ex) { ex.getCause().printStackTrace(); - nie.threadFuture.cancel(true); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + throw new PhasedTestingEventException("Un expected problem happened when waiting for th event to start.",e); } }