Thursday, September 15, 2011

Spring Roo - Error: One or more exceptions caught, see full set in UmbrellaException#getCauses

Problem

When trying to save a entity in spring roo (using in the web tier gwt) it showed the following error message:

Error: One or more exceptions caught, see full set in UmbrellaException#getCauses

Reason

The declaration of an empty constructor was causing the problem. The roo cause was not identified.

Solution

Remove the constructor. In my case the code was changed from:

public class A {
transient B b;

A(){
this.b = getStub();
}
...
}

to:

public class A {
transient B b= getStub();
...
}



Spring Roo - Error: One or more exceptions caught, see full set in UmbrellaException#getCauses

Problema

Ao tentar salvar uma entidade no spring roo (usando na camada de visão o gwt) apresentou o seguinte problema.

Error: One or more exceptions caught, see full set in UmbrellaException#getCauses

Motivo

A declaração de um construtor vazio estava ocasionando o problema. Mas a causa raiz não foi identificada.

Solução

Remover o construtor vazio. No meu caso foi modificado o código de:

public class A {
transient B b;

A(){
this.b = getStub();
}
...
}

para:

public class A {
transient B b= getStub();
...
}

Wednesday, September 14, 2011

Mock/Stub EntityManager in Spring Roo

Problem

Trying to create unit test to the method persist from a class created in Spring Roo using a stub do the EntityManger that is passed in the constructor as follows:


public class ClassATest {
    @Test
    public void whenPersistShoulCallClassB() throws Exception {
        
        Mockery contexto = new Mockery();
        final ClassB classB = contexto.mock(ClassB.class);
        
        final ClassA classA = 
            new ClassA(getEntityManagerStub(), classB);

        contexto.checking(new Expectations() {{
            one(classB).doSomething(classA);

        }
    });
        classA.persist();
        
        contexto.assertIsSatisfied();
    }

    private EntityManager getEntityManagerStub() {
        return new EntityManager() {
            ...
        }
    }
}
Source from ClassA

public class ClassA {
...

    public ClassA(EntityManager entityManager, ClassB classB) {
        this.entityManager = entityManager;
        this.classB = classB;
    }



    @Transactional
    public void persist() {
        if (this.entityManager == null) this.entityManager = entityManager();
     
        this.entityManager.persist(this);
     
        classB.doSomething(this);
     
    }

...
 }


This test works inside Eclipse, but doesn´t when called by maven, as a result of  mvn jetty:run-exploded.

Reason

Probably Spring Roo is injecting the EntityManager just before the call to the constructor.

Solution

Use of setter injection, as follows:

public class ClassATest {
    @Test
    public void whenPersistShoulCallClassB() throws Exception {
        
        Mockery contexto = new Mockery();
        final ClassB classB = contexto.mock(ClassB.class);
        
        final ClassA classA =
            new ClassA(classB);
        classeA.setEntityManager(getEntityManagerStub());
        
        contexto.checking(new Expectations() {{
            one(classB).doSomething(classeA);

        }
    });
        classeA.persist();
        
        contexto.assertIsSatisfied();
    }

    private EntityManager getEntityManagerStub() {

        return new EntityManager() {
            ...
        }

    }
}


Código da ClasseA


public class ClasseA {
...

    public ClasseA(ClasseB classeB) {
        this.classeB = classeB;
    }


    public void setEntityManager(EntityManager entityManager) {
        this.entityManager = entityManager;
    }




    @Transactional
    public void persist() {
        if (this.entityManager == null) this.entityManager = entityManager();
      
        this.entityManager.persist(this);
      
        classeB.doSomething(this);
      
    }

...
 }


There must be a more elegant solution that enables the utilization of construction injection. When I have time to research, I will post it.






Mock/Stub do EntityManager no Spring Roo

Problema

Ao tentar criar testes de unidade para o método persist de uma classe criada pelo Spring Roo, tentei utilizar um Stub para o EntityManager da seguinte forma:



public class ClasseATest {
    @Test
    public void aoPersistirDeveriaChamarClasseB() throws Exception {
        
        Mockery contexto = new Mockery();
        final ClasseB classeB = contexto.mock(ClasseB.class);
        
        final ClasseA classeA = 
            new ClasseA(getEntityManagerStub(), classeB);

        contexto.checking(new Expectations() {{
            one(classeB).fazerAlgo(classeA);

        }
    });
        classeA.persist();
        
        contexto.assertIsSatisfied();
    }

    private EntityManager getEntityManagerStub() {
        return new EntityManager() {
            ...
        }
    }
}
Código da ClasseA

public class ClasseA {
...

    public ClasseA(EntityManager entityManager, ClasseB classeB) {
        this.entityManager = entityManager;
        this.classeB = classeB;
    }



    @Transactional
    public void persist() {
        if (this.entityManager == null) this.entityManager = entityManager();
     
        this.entityManager.persist(this);
     
        classeB.fazerAlgo(this);
     
    }

...
 }


O teste funcionava quando era executado dentro de Eclipse, mas falhava quando era executado via maven, no momento da execução do mvn jetty:run-exploded.


Motivo

Provavelmente o spring roo está injetando o EntityManager logo após a chamada ao constructor.

Solução

Utilizar setter injection, como mostrado abaixo:


public class ClasseATest {
    @Test
    public void aoPersistirDeveriaChamarClasseB() throws Exception {
        
        Mockery contexto = new Mockery();
        final ClasseB classeB = contexto.mock(ClasseB.class);
        
        final ClasseA classeA =
            new ClasseA(classeB);
        classeA.setEntityManager(getEntityManagerStub());
        
        contexto.checking(new Expectations() {{
            one(classeB).fazerAlgo(classeA);

        }
    });
        classeA.persist();
        
        contexto.assertIsSatisfied();
    }

    private EntityManager getEntityManagerStub() {

        return new EntityManager() {
            ...
        }

    }
}


Código da ClasseA


public class ClasseA {
...

    public ClasseA(ClasseB classeB) {
        this.classeB = classeB;
    }


    public void setEntityManager(EntityManager entityManager) {
        this.entityManager = entityManager;
    }




    @Transactional
    public void persist() {
        if (this.entityManager == null) this.entityManager = entityManager();
      
        this.entityManager.persist(this);
      
        classeB.fazerAlgo(this);
      
    }

...
 }


Provavelmente deve existir uma solução mais elegante, que permita a utilização da injeção da dependência no construtor. Quando tiver tempo vou pesquisar e bloggar a solução.






Wednesday, June 15, 2011

Keep CMD Open

Problem

The cmd window close after finish the execution of a bat file. The desired behavior is that the cmd stay opened to the input of new comands.

Reason

It is the default behavior.

Solution

  • Create a bat file that will call another bat. Ex: keppCmdOpen.bat
  • In the file put the line: start "" fileWithCommands.bat /k
  • Create the file fileWithCommands.bat and add the desired commands.

Others

If the need is just to see the window, and not to input commands, there is no need to two bats. Just put the pause command at the end of the file.

More info:

http://answers.yahoo.com/question/index?qid=20090306121738AAkg8Ij
http://pt.w3support.net/index.php?db=so&id=905352

Manter cmd aberto

Problema

A janela do cmd se fecha ao final da execução das instruções em um arquivo bat. O comportamento desejado é que o cmd permaneça aberto para a entrada de novos comandos.

Motivo

Este é o comportamento padrão.

Solução

  • Crie um arquivo bat que irá chamar outro. Por exemplo: manterCmdAberto.bat
  • No arquivo criado adicione a seguinte linha: start "" arquivoComComandos.bat /k
  • Crie o arquivo arquivoComComandos.bat e adicione os comando desejados.
Outros

Se o que se deseja é apenas visualizar o conteúdo da janela cmd, e não entrar com comandos, não precisa dos dois arquivos. Simplesmente no segundo arquivo (arquivoComComandos.bat) adicione a linha: pause

Mais informações nos seguinte links:



Saturday, June 11, 2011

Spring Roo GWT application works in dev mode but not in production

Problem

A spring roo gwt application works in dev mode (mvn gwt:run) but not works in production mode (mvn tomcat:run or mvn jetty:run). When trying the late it shows a page with a rectangle with the message loading inside.

Reason

Solution

Assuming that the project is the sample that comes with roo expenses.roo. In STS (Spring Source Tool Suite):

  • Edit the project properties
  • Select Deployment Assembly
  • Click Add
  • Select Folder
  • Select target/extrack-0.1.0.BUILD-SNAPSHOT (or whatever your version is)
  • Click Finish
  • Right click on the project or the pom.xml
  • Select Run As -> Maven assembly:assembly
  • App should re-deploy to the server

This solution was originally posted here: http://forum.springsource.org/showthread.php?106292-Problem-with-expenses.roo-sample-and-STS-2.6.0

Aplicação Spring Roo GWT funciona em modo de desenvolvimento, mas não em produção

Problema

Uma aplicação spring roo configurada para utilizar o gwt funciona em modo de desenvolvimento (mvn gwt:run), mas não funciona quando se faz o deploy em produção (mvn tomcat:run ou mvn jetty:run). Quando se tenta o último mostra uma página com um quadrado e dentro a mensagem loading.

Motivo

Solução

Assumindo que o projeto é o sample que vem com o spring roo (expenses.roo). No STS (Spring Source Tool Suite):
  • Vá nas propriedades do projeto.
  • Selecione Deployment Assembly.
  • Clique em adicionar.
  • Selecione folder.
  • Selecione target/extrack-0.1.0.BUILD-SNAPSHOT.
  • Clique em finalizar.
  • Selecione Run As -> Maven assembly:assembly.


Atualização em 25 ago 2011

Por algum motivo os passos acima não estavam funcionando. Talvez tenha sido pela atualização do STS. Os passos abaixo resolveram o problema:

  • Retire o diretório target/extrack-0.1.0.BUILD-SNAPSHOT do Deployment Assembly como tinha feito acima.
  • Execute o comando mvn jetty:run-exploded.

Compilation error without editing source files in spring roo project

Problem

With no editing of source files from a spring roo project compilation errors appears. This errors are in the source controlled by roo (the aspects).


Sem que se tenha editado o código fonte de um projeto spring roo, problemas de compilação apareceram. Este problemas são na parte que o o roo controla e não devemos editar (Os aspectos).

Reason

Using a different version (older) of roo to work with the project that was created with a newer version of roo. I think it is a problem of roo. It should not allow to open a new projet with an old version of roo.

Solution

Revert the sources to the previous version. It is trivial if you are using a version control.

Erro de compilação em projeto spring roo sem ter editado arquivos

Problema

Sem que se tenha editado o código fonte de um projeto spring roo, problemas de compilação apareceram. Este problemas são na parte que o o roo controla e não devemos editar (Os aspectos).

Motivo

Utilizar o roo numa versão diferente (no caso mais antiga) da versão que foi utilizada para a criação do projeto. O próprio roo deveria verificar isto e nãom permitir abrir o projeto.

Solução

Voltar o código fonte a versão anterior. Trivial com a utilização de controle de versão.

Wednesday, June 8, 2011

Why insn´t Firefox picking up the GWT Developer Plugin when started from Junit using Webdriver?

Problem

When trying to access the GWT Development Environment (http://127.0.0.1:8888/ApplicationScaffold.html?gwt.codesvr=127.0.0.1:9997) using Wedriver inside Junit a page requesting the installation of GWT Development Plugin. Even with the plugin already installed.

Reason

By default, the Wedriver driver to Firefox use a clean profile( new FirefoxDriver()) without any extensions.

O driver para o Firefox que o Webdriver utiliza está com um perfil limpo (new FirefoxDriver()), sem nenhuma extensão.

Solution

To configure the profile to use the GWT Development Plugin as follows:

Download the plugin from https://dl-ssl.google.com/gwt/plugins/firefox/gwt-dev-plugin.xpi and put in some place in your computer.

Configure the driver to use the plugin:

FirefoxProfile profile = new FirefoxProfile();
profile.addExtension(new File("path to gwt-dev-plugin.xpi"));
WebDriver driver = new FirefoxDriver(profile);

More informationhere: http://groups.google.com/group/webdriver/browse_thread/thread/c4f0ee7529c0c70a?pli=1

Porque o Firefox não utiliza o GWT Developer Plugin quando iniciado do Junit utilizando o Webdriver?

Problema

Ao tentar acessar a URL para o ambiente do desenvolvimento do GWT (http://127.0.0.1:8888/ApplicationScaffold.html?gwt.codesvr=127.0.0.1:9997) utilizando o Webdriver dentro do Junit, é exibida página solicitando a instalação do plugin de desenvolvimento do GWT. Mesmo este plugin já tendo sido instalado.

Motivo

O driver para o Firefox que o Webdriver utiliza está com um perfil limpo (new FirefoxDriver()), sem nenhuma extensão.

Solução

Configurar para que o perfil utilizado possua o plugin de desenvolvimento do GWT. Segue roteiro:

Baixe o plugin a partir deste link: https://dl-ssl.google.com/gwt/plugins/firefox/gwt-dev-plugin.xpi e salve em algum local no computador

Configure o Firefox para utilizar o plugin:
FirefoxProfile profile = new FirefoxProfile();
profile.addExtension(new File("path to gwt-dev-plugin.xpi"));
WebDriver driver = new FirefoxDriver(profile);




Failed to connect to binary FirefoxBinary(C:\Program Files\Mozilla Firefox\firefox.exe) on port 7055 Problema Ao tentar executar os testes web utiliz

Problem

When trying to execute web tests with wedriver and Firefox the following error message appears:


org.openqa.selenium.WebDriverException: Failed to connect to binary FirefoxBinary(C:\Arquivos de programas\Mozilla Firefox\firefox.exe) on port 7055; process output follows:

##### IGeared_tavgpAVGTbApiComponent start
##### IGeared_tavgpAVGTbApiComponent init done
### go!ÿ
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.6.0_14'
Driver info: driver.version: firefox
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:91)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:117)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:64)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:100)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:92)
at br.com.leilao.estorias.concorrerleilao.DadoQueResgistrouConcorrerIpadComTempoParaDarLanceAhDezSegundosDeVencer.registrarConcorrenciaLeilao(DadoQueResgistrouConcorrerIpadComTempoParaDarLanceAhDezSegundosDeVencer.java:24)
at br.com.leilao.estorias.concorrerleilao.DadoQueResgistrouConcorrerIpadComTempoParaDarLanceAhDezSegundosDeVencer.registrarConcorrenciaAhProdutoNoLeilao(DadoQueResgistrouConcorrerIpadComTempoParaDarLanceAhDezSegundosDeVencer.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host localhost on port 7055 after 45000 ms
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:87)
... 29 more.


Reason

Not identified

Solution

To use the 3.6 version of Firefox (I was using 4.x). It is a workaround while a definitive solution is found. Other sugestions could be found in this link: http://groups.google.com/group/webdriver/browse_thread/thread/3d0bbb40cce5dfac/e4844f5f91882602?lnk=raot&pli=1

It no worked to me.

Failed to connect to binary FirefoxBinary(C:\Program Files\Mozilla Firefox\firefox.exe) on port 7055

Problema

Ao tentar executar os testes web utilizando o webdriver com o Firefox4.0, apresentou a seguinte mensagem de erro.

org.openqa.selenium.WebDriverException: Failed to connect to binary FirefoxBinary(C:\Arquivos de programas\Mozilla Firefox\firefox.exe) on port 7055; process output follows:

##### IGeared_tavgpAVGTbApiComponent start
##### IGeared_tavgpAVGTbApiComponent init done
### go!ÿ
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.v: '1.6.0_14'
Driver info: driver.version: firefox
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:91)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:117)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:64)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:100)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:92)
at br.com.leilao.estorias.concorrerleilao.DadoQueResgistrouConcorrerIpadComTempoParaDarLanceAhDezSegundosDeVencer.registrarConcorrenciaLeilao(DadoQueResgistrouConcorrerIpadComTempoParaDarLanceAhDezSegundosDeVencer.java:24)
at br.com.leilao.estorias.concorrerleilao.DadoQueResgistrouConcorrerIpadComTempoParaDarLanceAhDezSegundosDeVencer.registrarConcorrenciaAhProdutoNoLeilao(DadoQueResgistrouConcorrerIpadComTempoParaDarLanceAhDezSegundosDeVencer.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host localhost on port 7055 after 45000 ms
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:87)
... 29 more


Motivo

Desconhecido

Solução

Passei a utilizar a versão 3.6 do Firefox. Solução gambiarra enquanto outra melhor não aparece. Outras sugestões de solução, que não funcionaram no meu caso, podem ser encontradas neste link: http://groups.google.com/group/webdriver/browse_thread/thread/3d0bbb40cce5dfac/e4844f5f91882602?lnk=raot&pli=1

Thursday, June 2, 2011

Mostrando os aspectos gerados pelo spring roo no eclipse

Para mostrar os aspectos gerados pelo spring roo no eclipse, veja o seguinte link:

Inserir texto sem perder formatação no blogger

Problema

Texto com formatação parecida com html (xml por exemplo) direto no editor do blogger pode não ser exibido corretamente. Além disso é interessante a exibição de código fonte (programas) de forma parecida como seria apresentado nas IDEs (eclipse por exemplo).

Solução

Utilize o seguinte site para formatar o texto:

Problem when adding GWT to Spring Roo project

Problem


When trying to execute the spring roo command gwt setup, compilers problems as the following appears:

The import com.google.appengine cannot be resolved GaeAuthFilter.java /src/main/java/br/com/server/gae line 3 Java Problem

User cannot be resolved to a type UserServiceLocator.java /src/main/java/br/com/server/gae line 24 Java Problem

UserService cannot be resolved to a type GaeAuthFilter.java /src/main/java/br/com/server/gae line 21 Java Problem

UserServiceFactory cannot be resolved GaeAuthFilter.java /src/main/java/br/com/server/gae line 21 Java Problem


Reason

The command is not working properly. It should add a dependency to GAE.

Solution

Add this to the pow:

...


<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-1.0-sdk</artifactId>
<version>1.4.0</version>
</dependency>

...

Problema ao adicionar GWT a projeto Spring Roo

Problema

Ao executar o comando gwt setup para adicionar o GWT a projeto do spring roo, passa a apresentar erros de compilação, como:

The import com.google.appengine cannot be resolved GaeAuthFilter.java /src/main/java/br/com/server/gae line 3 Java Problem

User cannot be resolved to a type UserServiceLocator.java /src/main/java/br/com/server/gae line 24 Java Problem

UserService cannot be resolved to a type GaeAuthFilter.java /src/main/java/br/com/server/gae line 21 Java Problem

UserServiceFactory cannot be resolved GaeAuthFilter.java /src/main/java/br/com/server/gae line 21 Java Problem


Motivo

O comando do roo não está funcionando corretamente. Deveria adicionar ao pom a dependência ao GAE.

Solução

Adicione ao pom o seguinte:

...
com.google.appengine
appengine-api-1.0-sdk
1.4.0
...






Eclipse OutOfMemoryError: Java heap space

PROBLEM

Eclipse raises the following error when executing unit tests in JUnit:

java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:2882)
at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:100)
at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:515)
at java.lang.StringBuffer.append(StringBuffer.java:306)
at java.io.BufferedReader.readLine(BufferedReader.java:345)
at java.io.BufferedReader.readLine(BufferedReader.java:362)
at br.gov.al.sefaz.gcs.core.domain.particaodocumento.ParticaoDocumentoTest$AoValidarNoContextoInserir$ComConteudoMaior30Megas.inicializarContexto(ParticaoDocumentoTest.java:135)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:24)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)

REASON

The enviroment needs more memory to run the tests.

SOLUTION

In Eclipse:

Click Run->Run Configurations->...

In the Run Configuration View locate and select the test that you tried to run.

Select the Tab Arguments

In the VM field put the following: -Xms512m -Xmx1024m

Run the tests.

Problema Eclipse OutOfMemoryError: Java heap space

Problema

Apresentou a seguinte mensagem de erro ao tentar executar alguns testes de unidade:

java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:2882)
at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:100)
at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:515)
at java.lang.StringBuffer.append(StringBuffer.java:306)
at java.io.BufferedReader.readLine(BufferedReader.java:345)
at java.io.BufferedReader.readLine(BufferedReader.java:362)
at br.gov.al.sefaz.gcs.core.domain.particaodocumento.ParticaoDocumentoTest$AoValidarNoContextoInserir$ComConteudoMaior30Megas.inicializarContexto(ParticaoDocumentoTest.java:135)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:24)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)

Motivo

Falta de memória para execução de alguns testes.

Solução
Editar

Clique em Run->Run Configurations->...

Na tela Run Configurations localize e selecione o teste que tentou executar e não funcionou. Digite na caixa de testo no alto à esquerda.

Selecione a aba Arguments

No campo VM Arguments digite: -Xms512m -Xmx1024m

Execute os testes.