Yes. Because in test, transaction is open before test and close/rollback after test. In production code, the workInTransaction will make each batch run in individual transaction thus flush after each batch. In test it won't flush and clear will cause nothing being saved. 

Another option to fix this maybe calling flush before clear but I thought having a Transaction state check is safer(in case we change our code later i.e. roll batches into a single transaction, it won't cause exception) 

----- Original Message -----

> From: "Carlos Munoz" <notifications@github.com>
> To: "zanata/zanata-server" <zanata-server@noreply.github.com>
> Cc: "Patrick Huang" <pahuang@redhat.com>
> Sent: Wednesday, June 4, 2014 2:06:38 PM
> Subject: Re: [zanata-server] Optimize copytrans (#484)

> In
> zanata-war/src/test/java/org/zanata/service/impl/CopyTransServiceImplTest.java:
> > @@ -198,8 +197,11 @@ public void testCopyTrans(CopyTransExecution
> > execution) {
> >                  new
> >                  HCopyTransOptions(execution.getContextMismatchAction(),
> >                          execution.getDocumentMismatchAction(),
> >                          execution.getProjectMismatchAction());
> > -        CopyTransService copyTransService =
> > -                seam.autowire(CopyTransServiceImpl.class);
> > +        CopyTransServiceImpl copyTransService =
> > +                Mockito.spy(seam.autowire(CopyTransServiceImpl.class));
> > +        // so that we don't call session.clear
> > +        // (because in test transaction is not committed)
> > +
> >        Mockito.doReturn(false).when(copyTransService).isSafeToClearSession();

> So clearing the session in a test (mocked) environment will fail?

> —
> Reply to this email directly or view it on GitHub .