New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TemplateProcessor - IndexOutOfBoundsException #998

Closed
dcdh opened this Issue Feb 25, 2018 · 3 comments

Comments

Projects
None yet
2 participants
@dcdh
Contributor

dcdh commented Feb 25, 2018

Issue Overview

I am unable to execute test using Arquillian, OpenShift with a particular setup.

When executing my tests I obtain this exception

java.lang.IndexOutOfBoundsException: Source does not fit in dest

Expected Behaviour

Arquillian should setup to OpenShift a test environment and run my tests.

Current Behaviour

Fails with

java.lang.IndexOutOfBoundsException: Source does not fit in dest

Steps To Reproduce
  1. Have syncInstantiation defined to true
@Category(RequiresOpenshift.class)
@RequiresOpenshift
@RunWith(ArquillianConditionalRunner.class)
@Templates(templates = {@Template(url = "classpath:helloworld.yaml")}, syncInstantiation = true)
public class HelloWorldIT {
        @Test
	public void testServiceInvocation() {
        }
}
  1. Use this helloworld.yaml
apiVersion: v1
kind: Template
metadata:
  name: hello
objects:
- apiVersion: v1
  kind: DeploymentConfig
  metadata:
    name: helloworld-app
  spec:
    template:
      metadata:
        labels:
          name: helloworld-service2
      spec:
        containers:
        - image: openshift/hello-openshift
          imagePullPolicy: IfNotPresent
          name: helloworld-app
Additional Information

The code throwing the exception is located on the class openshift/openshift/src/main/java/org/arquillian/cube/openshift/impl/resources/TemplateProcessor.java

and concerns this method:

    public List<? super OpenShiftResource> processTemplateResources() {
        List<? extends OpenShiftResource> resources;
        final List<? super OpenShiftResource> processedResources = new ArrayList<>();
        templates = OpenShiftResourceFactory.getTemplates(getType());
        boolean sync_instantiation = OpenShiftResourceFactory.syncInstantiation(getType());

        /* Instantiate templates */
        for (Template template : templates) {
            resources = processTemplate(template);
            if (resources != null) {
                if (sync_instantiation) {
                /* synchronous template instantiation */
                    Collections.copy(processedResources, resources);
                } else {
                /* asynchronous template instantiation */
                    try {
                        delay(openShiftAdapter, resources);
                    } catch (Throwable t) {
                        throw new IllegalArgumentException(asynchronousDelayErrorMessage(), t);
                    }
                }
            }
        }

        return processedResources;
    }

It failed at this line:

Collections.copy(processedResources, resources);

because processedResources is empty and resources contains a list of the unique DeploymentConfig so Collections.copy throw an IndexOutOfBoundsException.

I guess you should replace this code by processedResources.addAll(resources)

Workaround

Set syncInstantiation defined to false

Regards, Damien

@dipak-pawar

This comment has been minimized.

Contributor

dipak-pawar commented Feb 26, 2018

Thanks for reporting @dcdh. I'll look into this.

@dipak-pawar dipak-pawar self-assigned this Feb 26, 2018

dipak-pawar added a commit to dipak-pawar/arquillian-cube that referenced this issue Feb 26, 2018

dipak-pawar added a commit to dipak-pawar/arquillian-cube that referenced this issue Feb 26, 2018

dipak-pawar added a commit that referenced this issue Feb 26, 2018

fix(#998): fixes collections.copy() for templateProcessor (#999)
* fix(#998): fixes collections.copy() for templateProcessor

* fixes failing tests by removing template params which is used by tests in same module

* changes method name and moves verification inline
@dcdh

This comment has been minimized.

Contributor

dcdh commented Feb 26, 2018

Please notice that I have used a DeploymentConfig as kind.

Others types of kind are working.

@dipak-pawar

This comment has been minimized.

Contributor

dipak-pawar commented Feb 27, 2018

@dcdh ohh I missed it. I will update config file for new test which I added as a part of #999 to use deployment config, so we can catch any issue with it in future.

@dipak-pawar dipak-pawar added this to the 1.15.3 milestone Mar 20, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment