Craig Tataryn <craiger@...> writes:

> 
> Craig Tataryn <craiger@...> writes:
> 
> > P.P.S. If I isolate my test outside of jBehave, everything works great 
> > (i.e. 
> > https://gist.github.com/1753833).  The JdbcTemplate code participates in 
> > the 
> > same transaction as the Service-level JPA code just like it should.
> > 
> > I'm stumped...
> > 
> 
> Analysing the log files between the working test and the JBehave test I can 
see
> the problem.  Spring binds its transaction manager to the "main" thread
> in both instances, however in the case of the JBehave test, the steps are
> executed in a another thread ("pool-1-thread-1" to be precise) and thus no
> transaction manager exists so a new one is created on-demand.
> 
> Is there a way I can work around this problem?  Can I have steps execute 
within
> the main thread instead of within the pool?
> 
> Craig.
> 
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
> 
>     http://xircles.codehaus.org/manage_email
> 
> 

FYI I managed to get it all working by implementing my own ExecutorService and 
telling the embedder to use it:

@Transactional("dwTransactionManager")
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "....")
public class RetrievePlayerInformationStoriesTest {
   
        @Before
        public void setup() {
                // SpringStepsFactory will comb the classpath for POJOs 
annotated with
                // @Given, @When... and add those as steps
                embedder = new PlayerStoriesEmbedder();
                //make sure the steps run on the current thread
                embedder.useExecutorService(new CurrentThreadExecutorService());
                embedder.useCandidateSteps(new SpringStepsFactory(embedder
                                .configuration(), 
context).createCandidateSteps());
        }
.
.
.
}

public class CurrentThreadExecutorService extends AbstractExecutorService {
        private boolean shutdown = false;
        private boolean terminated = false;
        @Override
        public void shutdown() { shutdown = true; }

        @Override
        public List<Runnable> shutdownNow() { return null; }

        @Override
        public boolean isShutdown() { return shutdown; }

        @Override
        public boolean isTerminated() { return terminated; }

        @Override
        public boolean awaitTermination(long timeout, TimeUnit unit) { 
terminated = true; return true; }

        @Override
        public void execute(Runnable command) {
                command.run();
        }
}








---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to