TESTNG ABNORMAL TERMINATION WITH JAVA DYNAMIC PROXY IMPLEMENTATION

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

TESTNG ABNORMAL TERMINATION WITH JAVA DYNAMIC PROXY IMPLEMENTATION

santhosh soma
HI Team,

We have implemented Java Dynamic Proxy to intercept the java method in case of any unknown popups to handle. ( For example, Device Os update popups and Device system apps notifications..etc).

We have observed that TestNg thread is getting interrupted and not picking up other methods or pending work/task on that thread.  


Following is our Invocation Handler which can intercept every appium command/Action during the run like Type, Click..etc

public class ListenersInvocationHandler implements InvocationHandler {

    

    private static final Logger LOG = LoggerFactory.getLogger(ListenersInvocationHandler.class);

    

    private ToolHelperFactory driver;

    private static final String invocableMethods = ListenerInvocableMethods.getCommaSeparatedValues();


    public ListenersInvocationHandler(ToolHelperFactory driver) {

        this.driver = driver;

    }

    

    @Override

    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

        

            try {

                return method.invoke(this.driver, args);  

            } catch (Exception ex) {

                if (invocableMethods.contains(method.getName())) {

                    String pageSource = this.driver.getAppiumDriver().getPageSource();

                    ListenerManager.invokeListeners(pageSource);

                    return method.invoke(this.driver, args);

                }

                throw ex;

        }


    }



In case of something went wrong with the above catch block we are getting the TestNG Runtime Exception and showing all Test methods as zero.


In following TestNG internal class(InvokeMethodRunnable) "t = new TestNGRuntimeException(e.getCause());".  The logs are not showing the Exception stack trace and not able to debug further.



package org.testng.internal;


import org.testng.IHookable;

import org.testng.ITestNGMethod;

import org.testng.ITestResult;


import java.lang.reflect.Method;


/**

 * A Runnable Method invoker.

 *

 * @author <a href="mailto:[hidden email]>the_mindstorm</a>

 */

public class InvokeMethodRunnable implements Runnable {

  private ITestNGMethod m_method = null;

  private Object m_instance = null;

  private Object[] m_parameters = null;

  private final IHookable m_hookable;

  private final ITestResult m_testResult;


  public InvokeMethodRunnable(ITestNGMethod thisMethod,

                              Object instance,

                              Object[] parameters,

                              IHookable hookable,

                              ITestResult testResult)

  {

    m_method = thisMethod;

    m_instance = instance;

    m_parameters = parameters;

    m_hookable = hookable;

    m_testResult = testResult;

  }


  @Override

  public void run() throws TestNGRuntimeException {

    // If there is an invocation time out, all the invocations need to be done within this

    // Runnable

    if (m_method.getInvocationTimeOut() > 0) {

      for (int i = 0; i < m_method.getInvocationCount(); i++) {

        runOne();

      }

    }

    else {

      runOne();

    }

  }


  private void runOne() {

    try {

      RuntimeException t = null;

      try {

        ConstructorOrMethod m = m_method.getConstructorOrMethod();

        if (m_hookable == null) {

          MethodInvocationHelper.invokeMethod(m.getMethod(), m_instance, m_parameters);

        } else {

          MethodInvocationHelper.invokeHookable(m_instance, m_parameters, m_hookable, m.getMethod(),

                                                m_testResult);

        }

      }

      catch(Throwable e) {

        t = new TestNGRuntimeException(e.getCause());

      }

      if(null != t) {

        Thread.currentThread().interrupt();

        throw t;

      }

    }

    finally {

      m_method.incrementCurrentInvocationCount();

    }

  }


  public static class TestNGRuntimeException extends RuntimeException {

    /**

     *

     */

    private static final long serialVersionUID = -8619899270785596231L;


    public TestNGRuntimeException(Throwable rootCause) {

      super(rootCause);

    }

  }

}


Note : We are using TestNG 6.10 Version. Please let us know if you need more details on the issue.


Thanks

Santhosh.


--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: TESTNG ABNORMAL TERMINATION WITH JAVA DYNAMIC PROXY IMPLEMENTATION

Krishnan Mahadevan
Santhosh, 

Can you please share a sample project that can be used to reproduce the problem ( preferably one that doesn't use any third party libraries such as appium). 

Also please retry using the latest released version of TestNG viz 6.14.3 as of today and see if the problem exists still. 

On Thu 14 Jun, 2018, 18:42 santhosh, <[hidden email]> wrote:
HI Team,

We have implemented Java Dynamic Proxy to intercept the java method in case of any unknown popups to handle. ( For example, Device Os update popups and Device system apps notifications..etc).

We have observed that TestNg thread is getting interrupted and not picking up other methods or pending work/task on that thread.  


Following is our Invocation Handler which can intercept every appium command/Action during the run like Type, Click..etc

public class ListenersInvocationHandler implements InvocationHandler {

    

    private static final Logger LOG = LoggerFactory.getLogger(ListenersInvocationHandler.class);

    

    private ToolHelperFactory driver;

    private static final String invocableMethods = ListenerInvocableMethods.getCommaSeparatedValues();


    public ListenersInvocationHandler(ToolHelperFactory driver) {

        this.driver = driver;

    }

    

    @Override

    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

        

            try {

                return method.invoke(this.driver, args);  

            } catch (Exception ex) {

                if (invocableMethods.contains(method.getName())) {

                    String pageSource = this.driver.getAppiumDriver().getPageSource();

                    ListenerManager.invokeListeners(pageSource);

                    return method.invoke(this.driver, args);

                }

                throw ex;

        }


    }



In case of something went wrong with the above catch block we are getting the TestNG Runtime Exception and showing all Test methods as zero.


In following TestNG internal class(InvokeMethodRunnable) "t = new TestNGRuntimeException(e.getCause());".  The logs are not showing the Exception stack trace and not able to debug further.



package org.testng.internal;


import org.testng.IHookable;

import org.testng.ITestNGMethod;

import org.testng.ITestResult;


import java.lang.reflect.Method;


/**

 * A Runnable Method invoker.

 *

 * @author <a href="mailto:[hidden email]>the_mindstorm</a>

 */

public class InvokeMethodRunnable implements Runnable {

  private ITestNGMethod m_method = null;

  private Object m_instance = null;

  private Object[] m_parameters = null;

  private final IHookable m_hookable;

  private final ITestResult m_testResult;


  public InvokeMethodRunnable(ITestNGMethod thisMethod,

                              Object instance,

                              Object[] parameters,

                              IHookable hookable,

                              ITestResult testResult)

  {

    m_method = thisMethod;

    m_instance = instance;

    m_parameters = parameters;

    m_hookable = hookable;

    m_testResult = testResult;

  }


  @Override

  public void run() throws TestNGRuntimeException {

    // If there is an invocation time out, all the invocations need to be done within this

    // Runnable

    if (m_method.getInvocationTimeOut() > 0) {

      for (int i = 0; i < m_method.getInvocationCount(); i++) {

        runOne();

      }

    }

    else {

      runOne();

    }

  }


  private void runOne() {

    try {

      RuntimeException t = null;

      try {

        ConstructorOrMethod m = m_method.getConstructorOrMethod();

        if (m_hookable == null) {

          MethodInvocationHelper.invokeMethod(m.getMethod(), m_instance, m_parameters);

        } else {

          MethodInvocationHelper.invokeHookable(m_instance, m_parameters, m_hookable, m.getMethod(),

                                                m_testResult);

        }

      }

      catch(Throwable e) {

        t = new TestNGRuntimeException(e.getCause());

      }

      if(null != t) {

        Thread.currentThread().interrupt();

        throw t;

      }

    }

    finally {

      m_method.incrementCurrentInvocationCount();

    }

  }


  public static class TestNGRuntimeException extends RuntimeException {

    /**

     *

     */

    private static final long serialVersionUID = -8619899270785596231L;


    public TestNGRuntimeException(Throwable rootCause) {

      super(rootCause);

    }

  }

}


Note : We are using TestNG 6.10 Version. Please let us know if you need more details on the issue.


Thanks

Santhosh.


--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
--

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.