Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Why am I getting a 503 error when running Integration Tests?

jarshwah January 21, 2016

I've written my own seraph plugin that authenticates to a private webservice. This worked fine in JIRA 6, but JIRA 7 has changed some APIs I was depending on (like UserUtil). My previous code was not created with the SDK or as a plugin, so I thought I'd try to build it properly. 

My unit tests run fine. The plugin is successfully deployed when I atlas-run or atlas-debug. But integration tests fail when I run atlas-integration-tests with the following (some names changed):

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.451 sec <<< FAILURE!
it.au.net.engage.JiraAuthWiredTest  Time elapsed: 0.451 sec  <<< ERROR!
java.lang.IllegalStateException: Could not find resource for test [http://josh-mbp:2990/jira/rest/atlassiantestrunner/1.0/runtest/it.au.net.engage.JiraAuthWiredTest]. Status: 503 - Service Unavailable
    at com.atlassian.plugins.osgi.test.AtlassianPluginsTestRunner.runViaRestCall(AtlassianPluginsTestRunner.java:107)
    at com.atlassian.plugins.osgi.test.AtlassianPluginsTestRunner.run(AtlassianPluginsTestRunner.java:75)
    at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
    at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)

Results :
Tests in error:
  it.au.net.engage.JiraAuthWiredTest: Could not find resource for test [http://localhost:2990/jira/rest/atlassiantestrunner/1.0/runtest/it.au.net.engage.JiraAuthWiredTest]. Status: 503 - Service Unavailable
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0

 

I don't get what I'm doing wrong here. Some supporting code (with obvious bits removed for brevity):

package it.au.net.engage;

import org.junit.Test;
import org.junit.runner.RunWith;
import com.atlassian.plugins.osgi.test.AtlassianPluginsTestRunner;
import com.atlassian.sal.api.ApplicationProperties;
import au.net.engage.api.IJiraAuth;
import static org.junit.Assert.assertEquals;

@RunWith(AtlassianPluginsTestRunner.class)
public class JiraAuthWiredTest
{
AuthWiredTest(ApplicationProperties applicationProperties, IJiraAuth myPluginComponent) {
        this.applicationProperties = applicationProperties;
        this.authComponent = myPluginComponent;
}
    @Test
    public void testMyName()
    {
        assertEquals("names do not match!", "myComponent: " + applicationProperties.getDisplayName(), authComponent.getName());
    }
}
 
<atlassian-plugin key="${project.groupId}.${project.artifactId}-tests" name="${project.name}" plugins-version="2">
    <plugin-info>
        <description>${project.description}</description>
        <version>${project.version}</version>
        <vendor name="${project.organization.name}" url="${project.organization.url}" />
    </plugin-info>
    <component-import key="myPluginComponent" interface="au.net.engage.api.IJiraAuth"/>
    <component-import key="applicationProperties" interface="com.atlassian.sal.api.ApplicationProperties" />
</atlassian-plugin>
 
 
# From the POM:
<!-- Add package to export here -->
                        <Export-Package>
                            au.net.engage.api,
                        </Export-Package>
                        <Import-Package>
                            org.springframework.osgi.*;resolution:="optional",
                          org.eclipse.gemini.blueprint.*;resolution:="optional",
                            *;version="0";resolution:="optional"
                        </Import-Package>

 

 

 

5 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
eXtensi Admin February 21, 2016

that is a bug in the latest SDK

Anyway atlas-integration-test isn't good for development as it takes couple of minutes to start the container. I'd only consider it with a CI.

 

Here's a solution to configure and run integration tests in couple of seconds smile and from IDE or cmd

 

Start JIRA using

atlas-debug --Dbaseurl=http://localhost:2990/jira

 

Make sure You export relevant packages in Your pom

<instructions>
  <Export-Package>...

 

And import relevant packages in the src/test/resources/atlassian-plugin.xml

<plugin-info>
	<description>${project.description}</description>
	...
	<bundle-instructions> 
		<Import-Package>
			com.yourplugin.something.*,
		</Import-Package>	
	</bundle-instructions>
</plugin-info>

 

Reinstall the app using quickreload

rmdir target\classes /s /q
atlas-mvn package -DskipTests

 

Go to http://localhost:2990/jira/plugins/servlet/system/console

and find Your com.yourplugin.something.yourclass-test and see if all dependencies have been met.

 

 

Run Unit tests

Option nb 1 - console

atlas-remote-test --server localhost -p 2990 --context-path JIRA

 

Option nb 2 - rest api

use the http://localhost:2990/jira/plugins/servlet/restbrowser#/resource/atlassiantestrunner-1-0-testlist-bundlesymbolicname to identify test classes

 

And test console to execute

http://localhost:2990/jira/plugins/servlet/restbrowser#/resource/atlassiantestrunner-1-0-runtestfromconsole-testclassname

 

You'll get

{
  "bundleSymbolicName": "com.yourplugin.something-tests",
  "testResultDetail": {
    "testResult": {
      "fCount": {
        "value": 0
      },
      "fIgnoreCount": {
        "value": 0
      },
      "fFailures": [],
      "fRunTime": 0,
      "fStartTime": 0
    },
    "passedMethods": [
      "messageIsValid"
    ],
    "ignoredMethods": [],
    "failedMethods": {},
    "classname": "com.yourplugin.something.yourclassTest",
    "divId": "ut-com-yourplugin-something-test",
    "allTestMethods": []
  }
}

 

 

Option 3 - web browser & rest

http://localhost:2990/jira/rest/atlassiantestrunner/1.0/runtest/com.yourplugin.something.yourclassTest

Will display the result in the browser - good for rest tests



Option nb 4 - Eclipse smile


Create new junit run cfg with baseurl argument

 

image2016-2-22 23:37:56.png

And run all Your tests.

 

 

@RunWith(AtlassianPluginsTestRunner.class) test will be executed in the container.

 

1 vote
Daniel John
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 9, 2016

Hi,

JIRA now starts asynchronously. Therefore you have to wait until JIRA is ready.

package it.com.decadis.test.helper;
import org.apache.log4j.Logger;
import org.apache.wink.client.Resource;
import org.apache.wink.client.RestClient;
import org.junit.BeforeClass;
import org.junit.Test;
 
public class LittleJira7Helper
{
    private static final Logger log = Logger.getLogger(LittleJira7Helper.class);
 
    @BeforeClass
    public static void waitForJira7()
    {
        String testApi = System.getProperty("baseurl") + "/rest/api/2/field";
        RestClient restClient = new RestClient();
        Resource resource = restClient.resource(testApi);
        int returnCode = 503;
        while ( returnCode == 503 )
        {
            returnCode = resource.get().getStatusCode();
            if ( returnCode == 503 )
            {
                log.error("JIRA is still unavailable! Waiting 5 seconds...");
            }
            try
            {
                Thread.sleep(5000);
            } catch (InterruptedException e)
            {
            }
        }
    }
 
    @Test
    public void test()
    {
        // JIRA is now ready...
    }
}

I had the same problem but running this code before every test helps.

 

Kind regards,

Daniel John

Guillaume Vial July 13, 2016

Hello,

I had the same problem. Thank you Daniel for your approach, it helped me a lot to fix it !

I have overriden the default run() method of AtlassianPluginsTestRunner class like that :

 

package it.com.holydev.env.common;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import org.apache.wink.client.Resource;
import org.apache.wink.client.RestClient;
import org.junit.runner.notification.RunNotifier;
import org.junit.runners.model.InitializationError;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.atlassian.plugins.osgi.test.AtlassianPluginsTestRunner;

public class HolydevAtlassianPluginsTestRunner extends AtlassianPluginsTestRunner {
    
	private static final Logger log = LoggerFactory.getLogger(AtlassianPluginsTestRunner.class);
    
	public void waitForJira7() {
		String testApi = System.getProperty("baseurl")
		+ "/rest/atlassiantestrunner/1.0/runtest/it.com.holydev.env.application.EnvironmentApplicationManagerTest";
		RestClient restClient = new RestClient();
		Resource resource = restClient.resource(testApi);
		log.error("Resource status code:" + resource.get().getStatusCode());
		int returnCode = 503;
		while (returnCode == 503) {
	    		returnCode = resource.get().getStatusCode();
	    		if (returnCode == 503) {
					log.error("JIRA is still unavailable! Waiting 5 seconds...");
	    		}
	    		try {
					Thread.sleep(5000);
	    		} catch (InterruptedException e) {}
		}
    }
    @Override
    public void run(final RunNotifier notifier) {
		waitForJira7();
		super.run(notifier);
    }
    public HolydevAtlassianPluginsTestRunner(Class<?> klass) throws InitializationError, FileNotFoundException, IOException {
		super(klass);
}

And I start all my integration tests with this runner. It works fine for me with JIRA 7 now.

1 vote
Mykhailo February 11, 2016

I also have the same error! @Josh Smeaton, did you find the solution?

jarshwah February 14, 2016

Unfortunately not, but I'm glad that I'm not the only one. Maybe it's a versioning issue or something.

I did start the project as a generic (universal?) plugin though, then modified it by hand to be a JIRA only plugin. What kind of plugin did you generate?

Mykhailo February 18, 2016

I created my plugin using "atlas-create-jira-plugin" command. All the wired tests run well on JIRA 6.0.4 and SDK 5.0.3.

After JIRA 7 was released I had to switch to SDK 6.1.0. I was able to run the JIRA with "atlas-debug", but "atlas-integration-test" failed with 503 error.

0 votes
Tomasz Kanafa
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 6, 2016

you could pass 

com.atlassian.jira.startup.LauncherContextListener.SYNCHRONOUS=true

 

 

parameter to maven-amps-plugin to disable asynchronous JIRA start eg:.

 

<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-amps-plugin</artifactId>
<configuration>
...
<jvmArgs>-Dcom.atlassian.jira.startup.LauncherContextListener.SYNCHRONOUS=true</jvmArgs>
0 votes
eXtensi Admin February 22, 2016

the SDK seems to be broken see the resolution below

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events