From users-return-13324-apmail-tomee-users-archive=tomee.apache.org@tomee.apache.org Tue Sep 3 15:45:50 2013 Return-Path: X-Original-To: apmail-tomee-users-archive@www.apache.org Delivered-To: apmail-tomee-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id AB0F010496 for ; Tue, 3 Sep 2013 15:45:50 +0000 (UTC) Received: (qmail 36265 invoked by uid 500); 3 Sep 2013 15:45:50 -0000 Delivered-To: apmail-tomee-users-archive@tomee.apache.org Received: (qmail 35923 invoked by uid 500); 3 Sep 2013 15:45:45 -0000 Mailing-List: contact users-help@tomee.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@tomee.apache.org Delivered-To: mailing list users@tomee.apache.org Received: (qmail 35915 invoked by uid 99); 3 Sep 2013 15:45:44 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Sep 2013 15:45:44 +0000 X-ASF-Spam-Status: No, hits=2.8 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS,URI_HEX X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of rmannibucau@gmail.com designates 209.85.212.52 as permitted sender) Received: from [209.85.212.52] (HELO mail-vb0-f52.google.com) (209.85.212.52) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Sep 2013 15:45:41 +0000 Received: by mail-vb0-f52.google.com with SMTP id f12so3907907vbg.25 for ; Tue, 03 Sep 2013 08:45:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=07axDbtvD+Q02Iw2F7jU9NFLr+2Sz/CQn/c4l1+CoNY=; b=C+Ja1Dk57AdHWYH97QajdxHiwfUs7bNBYIUrTIRQzaL9zvS7xyZUZ99M9zqkJowu88 vo/CE73StrmCuuw0UFNU4teHBIbwTGlKSGwNZhGBtf4YFsD6nQXbHNmgoVkBjKlSj9C/ rMAQWNSyAi12xELdpS+cT02xC/QlfGY7e68XVjF02+JJRsSHuINacPEfzyHT+FRfKQBf apPpHaomb2UBB24BIxb9PV8uzORwfImOTD/hZ3OxlVtsQ40/lSXDKCwcXPt8hIwOuHfv BIHvyGRBA0X5D2mB5dSeL6iUP68xLud8ZZSqeqOoCw1ax08Ulv8vgQrz28jbBycvL4g0 reeg== X-Received: by 10.58.208.130 with SMTP id me2mr29076658vec.13.1378223119067; Tue, 03 Sep 2013 08:45:19 -0700 (PDT) MIME-Version: 1.0 Received: by 10.58.209.3 with HTTP; Tue, 3 Sep 2013 08:44:58 -0700 (PDT) In-Reply-To: References: <1378113591163-4664940.post@n4.nabble.com> <04B1388F4CE22F4088DD2BA3E4C4CDBE4E5CF183@otmucxg20.opentext.net> <1378132535528-4664948.post@n4.nabble.com> <1378193533874-4664963.post@n4.nabble.com> <04B1388F4CE22F4088DD2BA3E4C4CDBE4E5CF51B@otmucxg20.opentext.net> From: Romain Manni-Bucau Date: Tue, 3 Sep 2013 17:44:58 +0200 Message-ID: Subject: Re: AW: AW: Fired cron trigger not available To: "users@tomee.apache.org" Content-Type: multipart/alternative; boundary=047d7bdc192c6ef78804e57c9364 X-Virus-Checked: Checked by ClamAV on apache.org --047d7bdc192c6ef78804e57c9364 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable here is a sample test http://svn.apache.org/repos/asf/tomee/tomee/trunk/container/openejb-core/sr= c/test/java/org/apache/openejb/timer/QuartzPersistenceForEJBTimersTest.java it uses this init script: http://svn.apache.org/repos/asf/tomee/tomee/trunk/container/openejb-core/sr= c/test/resources/import-QuartzPersistenceForEJBTimersDBNoTx.sql *Romain Manni-Bucau* *Twitter: @rmannibucau * *Blog: **http://rmannibucau.wordpress.com/* *LinkedIn: **http://fr.linkedin.com/in/rmannibucau* *Github: https://github.com/rmannibucau* 2013/9/3 Romain Manni-Bucau > /* > * Licensed to the Apache Software Foundation (ASF) under one or more > * contributor license agreements. See the NOTICE file distributed with > * this work for additional information regarding copyright ownership. > * The ASF licenses this file to You under the Apache License, Version 2.0 > * (the "License"); you may not use this file except in compliance with > * the License. You may obtain a copy of the License at > * > * http://www.apache.org/licenses/LICENSE-2.0 > * > * Unless required by applicable law or agreed to in writing, software > * distributed under the License is distributed on an "AS IS" BASIS, > * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= . > * See the License for the specific language governing permissions and > * limitations under the License. > */ > package org.apache.openejb.resource.jdbc; > > import org.apache.openejb.jee.EjbJar; > import org.apache.openejb.jee.SingletonBean; > import org.apache.openejb.junit.ApplicationComposer; > import org.apache.openejb.testing.Configuration; > import org.apache.openejb.testing.Module; > import org.apache.openejb.resource.jdbc.managed.local.ManagedConnection; > import org.junit.After; > import org.junit.BeforeClass; > import org.junit.Test; > import org.junit.runner.RunWith; > > import javax.annotation.Resource; > import javax.ejb.EJB; > import javax.ejb.EJBContext; > import javax.ejb.LocalBean; > import javax.ejb.Singleton; > import javax.ejb.TransactionAttribute; > import javax.ejb.TransactionAttributeType; > import javax.sql.DataSource; > import javax.transaction.Transaction; > import java.lang.reflect.Field; > import java.sql.Connection; > import java.sql.DriverManager; > import java.sql.ResultSet; > import java.sql.SQLException; > import java.sql.Statement; > import java.util.Map; > import java.util.Properties; > > import static org.junit.Assert.assertEquals; > import static org.junit.Assert.assertFalse; > import static org.junit.Assert.assertTrue; > > @RunWith(ApplicationComposer.class) > public class ManagedDataSourceTest { > private static final String URL =3D > "jdbc:hsqldb:mem:managed;hsqldb.tx=3DMVCC"; // mvcc otherwise multiple > transaction tests will fail > private static final String USER =3D "sa"; > private static final String PASSWORD =3D ""; > private static final String TABLE =3D "PUBLIC.MANAGED_DATASOURCE_TEST= "; > > @EJB > private Persister persistManager; > > @Resource > private DataSource ds; > > @BeforeClass > public static void createTable() throws SQLException, > ClassNotFoundException { > Class.forName("org.hsqldb.jdbcDriver"); > > final Connection connection =3D DriverManager.getConnection(URL, > USER, PASSWORD); > final Statement statement =3D connection.createStatement(); > statement.execute("CREATE TABLE " + TABLE + "(ID INTEGER)"); > statement.close(); > connection.commit(); > connection.close(); > } > > @Configuration > public Properties config() { > final Properties p =3D new Properties(); > p.put("openejb.jdbc.datasource-creator", "dbcp-alternative"); > > p.put("managed", "new://Resource?type=3DDataSource"); > p.put("managed.JdbcDriver", "org.hsqldb.jdbcDriver"); > p.put("managed.JdbcUrl", URL); > p.put("managed.UserName", USER); > p.put("managed.Password", PASSWORD); > p.put("managed.JtaManaged", "true"); > return p; > } > > @Module > public EjbJar app() throws Exception { > return new EjbJar() > .enterpriseBean(new > SingletonBean(Persister.class).localBean()) > .enterpriseBean(new > SingletonBean(OtherPersister.class).localBean()); > } > > @LocalBean > @Singleton > @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) > public static class OtherPersister { > @Resource(name =3D "managed") > private DataSource ds; > > @Resource > private EJBContext context; > > public void save() throws SQLException { > ManagedDataSourceTest.save(ds, 10); > } > > public void saveAndRollback() throws SQLException { > ManagedDataSourceTest.save(ds, 11); > context.setRollbackOnly(); > } > } > > @LocalBean > @Singleton > public static class Persister { > @Resource(name =3D "managed") > private DataSource ds; > > @Resource > private EJBContext context; > > @EJB > private OtherPersister other; > > public void save() throws SQLException { > ManagedDataSourceTest.save(ds, 1); > } > > public void saveAndRollback() throws SQLException { > ManagedDataSourceTest.save(ds, 2); > context.setRollbackOnly(); > } > > public void saveTwice() throws SQLException { > ManagedDataSourceTest.save(ds, 3); > ManagedDataSourceTest.save(ds, 4); > } > > public void rollbackMultipleSave() throws SQLException { > ManagedDataSourceTest.save(ds, 5); > ManagedDataSourceTest.save(ds, 6); > context.setRollbackOnly(); > } > > public void saveInThisTxAndAnotherOne() throws SQLException { > ManagedDataSourceTest.save(ds, 7); > other.save(); > } > > public void saveInThisTxAndRollbackInAnotherOne() throws > SQLException { > ManagedDataSourceTest.save(ds, 8); > other.saveAndRollback(); > } > } > > @Test > public void commit() throws SQLException { > persistManager.save(); > assertTrue(exists(1)); > } > > @Test > public void rollback() throws SQLException { > persistManager.saveAndRollback(); > assertFalse(exists(2)); > } > > @Test > public void commit2() throws SQLException { > persistManager.saveTwice(); > assertTrue(exists(3)); > assertTrue(exists(4)); > } > > @Test > public void rollback2() throws SQLException { > persistManager.rollbackMultipleSave(); > assertFalse(exists(5)); > assertFalse(exists(6)); > } > > @Test > public void saveDifferentTx() throws SQLException { > persistManager.saveInThisTxAndAnotherOne(); > assertTrue(exists(7)); > assertTrue(exists(10)); > } > > @Test > public void saveRollbackDifferentTx() throws SQLException { > persistManager.saveInThisTxAndRollbackInAnotherOne(); > assertTrue(exists(8)); > assertFalse(exists(12)); > } > > @After > public void checkTxMapIsEmpty() throws Exception { // avoid memory le= ak > final Field map =3D > ManagedConnection.class.getDeclaredField("CONNECTION_BY_TX_BY_DS"); > map.setAccessible(true); > final Map> instance =3D > (Map> ) map.get(null); > assertEquals(1, instance.size()); > assertEquals(0, instance.values().iterator().next().size()); > } > > private static boolean exists(int id) throws SQLException { > final Connection connection =3D DriverManager.getConnection(URL, > USER, PASSWORD); > final Statement statement =3D connection.createStatement(); > final ResultSet result =3D statement.executeQuery("SELECT count(*= ) > AS NB FROM " + TABLE + " WHERE ID =3D " + id); > try { > assertTrue(result.next()); > return result.getInt(1) =3D=3D 1; > } finally { > statement.close(); > connection.close(); > } > } > > private static void save(final DataSource ds, int id) throws > SQLException { > execute(ds, "INSERT INTO " + TABLE + "(ID) VALUES(" + id + ")"); > } > > private static void execute(final DataSource ds, final String sql) > throws SQLException { > final Connection connection =3D ds.getConnection(); > final Statement statement =3D connection.createStatement(); > statement.executeUpdate(sql); > statement.close(); > connection.close(); > } > } > Le 3 sept. 2013 12:01, "tschuler" a =E9crit= : > > Hi Romain! >> >> Can you directly post the ManagedDataSourceTest.java file because I got >> connection timeouts accessing the apache tomee svn repository. >> >> Best regards, >> Thomas >> >> Von: Romain Manni-Bucau [via OpenEJB] [mailto: >> ml-node+s979440n4664964h94@n4.nabble.com] >> Gesendet: Dienstag, 3. September 2013 09:50 >> An: Thomas Schuler >> Betreff: Re: AW: Fired cron trigger not available >> >> Hi >> >> This test defines a datasource called 'managed' >> >> http://svn.apache.org/repos/asf/tomee/tomee/trunk/container/openejb-core= /src/test/java/org/apache/openejb/resource/jdbc/ManagedDataSourceTest.java >> >> Just add in src/test/resources a file import-managed.sql with a statemen= t >> by line created from hsql scripts of quartz >> Le 3 sept. 2013 09:33, "tschuler" <[hidden >> email]> a =E9crit = : >> >> > Hi Romain! >> > >> > As I am neither familiar with the application composer and the in memo= ry >> > database: >> > Can you provide me a running example how to initialize and use the in >> > memory >> > database for tests? >> > >> > Best regards, >> > Thomas >> > >> > >> > >> > -- >> > View this message in context: >> > >> http://openejb.979440.n4.nabble.com/Fired-cron-trigger-not-available-tp4= 664936p4664963.html >> > Sent from the OpenEJB User mailing list archive at Nabble.com. >> > >> >> ________________________________ >> If you reply to this email, your message will be added to the discussion >> below: >> >> http://openejb.979440.n4.nabble.com/Fired-cron-trigger-not-available-tp4= 664936p4664964.html >> To unsubscribe from Fired cron trigger not available, click here< >> http://openejb.979440.n4.nabble.com/template/NamlServlet.jtp?macro=3Duns= ubscribe_by_code&node=3D4664936&code=3DdGhvbWFzLnNjaHVsZXJAb3BlbnRleHQuY29t= fDQ2NjQ5MzZ8LTE4NTIyNTQ0OTI=3D >> >. >> NAML< >> http://openejb.979440.n4.nabble.com/template/NamlServlet.jtp?macro=3Dmac= ro_viewer&id=3Dinstant_html%21nabble%3Aemail.naml&base=3Dnabble.naml.namesp= aces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.we= b.template.NodeNamespace&breadcrumbs=3Dnotify_subscribers%21nabble%3Aemail.= naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aema= il.naml >> > >> >> >> >> >> -- >> View this message in context: >> http://openejb.979440.n4.nabble.com/Fired-cron-trigger-not-available-tp4= 664936p4664969.html >> Sent from the OpenEJB User mailing list archive at Nabble.com. > > --047d7bdc192c6ef78804e57c9364--