bitronix.tm.TransactionManagerServices Java Examples
The following examples show how to use
bitronix.tm.TransactionManagerServices.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UnSupportedCombinationsWithClusteredCacheTest.java From ehcache3 with Apache License 2.0 | 6 votes |
@Test public void testClusteredCacheWithXA() throws Exception { TransactionManagerServices.getConfiguration().setJournal("null"); BitronixTransactionManager transactionManager = TransactionManagerServices.getTransactionManager(); try { CacheManagerBuilder.newCacheManagerBuilder() .using(new LookupTransactionManagerProviderConfiguration(BitronixTransactionManagerLookup.class)) .with(ClusteringServiceConfigurationBuilder.cluster(URI.create("terracotta://localhost/my-application")).autoCreate(c -> c)) .withCache("xaCache", CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, ResourcePoolsBuilder.newResourcePoolsBuilder() .with(ClusteredResourcePoolBuilder.clusteredDedicated("primary-server-resource", 8, MemoryUnit.MB)) ) .withService(new XAStoreConfiguration("xaCache")) .build() ) .build(true).close(); fail("Expected StateTransitionException"); } catch (StateTransitionException e) { assertThat(e.getCause().getCause().getMessage(), is("Unsupported resource type : interface org.ehcache.clustered.client.config.DedicatedClusteredResourcePool")); } transactionManager.shutdown(); }
Example #2
Source File: MicroserviceResourceProducerTest.java From genericconnector with Apache License 2.0 | 6 votes |
@Test public void testFind() throws ResourceException, NotSupportedException, SystemException { MicroserviceResourceFactory msrFactory = mock(MicroserviceResourceFactory.class); MicroserviceXAResource xa = new MicroserviceXAResource("a", mock(CommitRollbackCallback.class)); when(msrFactory.build()).thenReturn(xa); MicroserviceResourceProducer.registerMicroserviceResourceFactory("a", msrFactory); MicroserviceResourceProducer producer = MicroserviceResourceProducer.getProducers().values().iterator().next(); BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager(); try{ tm.begin(); //TEST producer.getTransactionAssistant(); //enlists resource into TX and means we can then go find it XAResource found = producer.findXAResourceHolder(xa).getXAResource(); assertEquals(xa, found); }finally{ tm.rollback(); } }
Example #3
Source File: StatefulSerializerTest.java From ehcache3 with Apache License 2.0 | 6 votes |
@Test public void testXAWithStatefulSerializer() throws Exception { BitronixTransactionManager manager = TransactionManagerServices.getTransactionManager(); try (CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder() .using(new LookupTransactionManagerProviderConfiguration( BitronixTransactionManagerLookup.class)) .withCache("xaCache", CacheConfigurationBuilder .newCacheConfigurationBuilder(Long.class, Person.class, ResourcePoolsBuilder.heap(5)) .withExpiry(ExpiryPolicyBuilder.noExpiration()).withService(new XAStoreConfiguration("xaCache")) .build()) .build(true)) { Cache<Long, Person> cache = cacheManager.getCache("xaCache", Long.class, Person.class); manager.begin(); cache.put(1L, new Person("James", 42)); manager.commit(); manager.begin(); assertNotNull(cache.get(1L)); manager.commit(); } finally { manager.shutdown(); } }
Example #4
Source File: XA107Test.java From ehcache3 with Apache License 2.0 | 6 votes |
@Test public void testXAWorksWithJsr107() throws Exception { BitronixTransactionManager transactionManager = TransactionManagerServices.getTransactionManager(); URI uri = getClass().getResource("/configs/simple-xa.xml").toURI(); CacheManager cacheManager = Caching.getCachingProvider().getCacheManager(uri, getClass().getClassLoader()); Cache<String, String> xaCache = cacheManager.getCache("xaCache", String.class, String.class); transactionManager.begin(); { xaCache.put("key", "one"); } transactionManager.commit(); cacheManager.close(); }
Example #5
Source File: XACacheTest.java From ehcache3 with Apache License 2.0 | 5 votes |
@Test public void testRecoveryWithInflightTx() throws Exception { CacheConfigurationBuilder<Long, String> cacheConfigurationBuilder = CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, newResourcePoolsBuilder() .heap(10, EntryUnit.ENTRIES) .offheap(10, MemoryUnit.MB)); cacheManager = CacheManagerBuilder.newCacheManagerBuilder() .withCache("txCache1", cacheConfigurationBuilder.withService(new XAStoreConfiguration("txCache1")).build()) .withCache("txCache2", cacheConfigurationBuilder.withService(new XAStoreConfiguration("txCache2")).build()) .using(new LookupTransactionManagerProviderConfiguration(BitronixTransactionManagerLookup.class)) .build(true); Cache<Long, String> txCache1 = cacheManager.getCache("txCache1", Long.class, String.class); Cache<Long, String> txCache2 = cacheManager.getCache("txCache2", Long.class, String.class); transactionManager.begin(); { txCache1.put(1L, "one"); txCache2.put(1L, "un"); } transactionManager.commit(); transactionManager.begin(); { txCache1.remove(1L); txCache2.remove(1L); } transactionManager.getCurrentTransaction().addTransactionStatusChangeListener((oldStatus, newStatus) -> { if (newStatus == Status.STATUS_PREPARED) { Recoverer recoverer = TransactionManagerServices.getRecoverer(); recoverer.run(); assertThat(recoverer.getCommittedCount(), is(0)); assertThat(recoverer.getRolledbackCount(), is(0)); } }); transactionManager.commit(); }
Example #6
Source File: XmlConfigTest.java From ehcache3 with Apache License 2.0 | 5 votes |
@Test public void testSimpleConfig() throws Exception { TransactionManagerServices.getConfiguration().setJournal("null").setServerId("XmlConfigTest"); BitronixTransactionManager transactionManager = TransactionManagerServices.getTransactionManager(); final URL myUrl = this.getClass().getResource("/configs/simple-xa.xml"); Configuration xmlConfig = new XmlConfiguration(myUrl); CacheManager myCacheManager = CacheManagerBuilder.newCacheManager(xmlConfig); myCacheManager.init(); myCacheManager.close(); transactionManager.shutdown(); }
Example #7
Source File: XAGettingStarted.java From ehcache3 with Apache License 2.0 | 5 votes |
@Test public void testXACacheWithXMLConfig() throws Exception { // tag::testXACacheWithXMLConfig[] BitronixTransactionManager transactionManager = TransactionManagerServices.getTransactionManager(); // <1> URL myUrl = this.getClass().getResource("/docs/configs/xa-getting-started.xml"); // <2> Configuration xmlConfig = new XmlConfiguration(myUrl); // <3> CacheManager myCacheManager = CacheManagerBuilder.newCacheManager(xmlConfig); // <4> myCacheManager.init(); myCacheManager.close(); transactionManager.shutdown(); // end::testXACacheWithXMLConfig[] }
Example #8
Source File: XAGettingStarted.java From ehcache3 with Apache License 2.0 | 5 votes |
@Test public void testXACacheWithThreeTiers() throws Exception { // tag::testXACacheWithThreeTiers[] BitronixTransactionManager transactionManager = TransactionManagerServices.getTransactionManager(); // <1> PersistentCacheManager persistentCacheManager = CacheManagerBuilder.newCacheManagerBuilder() .using(new LookupTransactionManagerProviderConfiguration(BitronixTransactionManagerLookup.class)) // <2> .with(CacheManagerBuilder.persistence(new File(getStoragePath(), "testXACacheWithThreeTiers"))) // <3> .withCache("xaCache", CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, // <4> ResourcePoolsBuilder.newResourcePoolsBuilder() // <5> .heap(10, EntryUnit.ENTRIES) .offheap(10, MemoryUnit.MB) .disk(20, MemoryUnit.MB, true) ) .withService(new XAStoreConfiguration("xaCache")) // <6> .build() ) .build(true); Cache<Long, String> xaCache = persistentCacheManager.getCache("xaCache", Long.class, String.class); transactionManager.begin(); // <7> { xaCache.put(1L, "one"); // <8> } transactionManager.commit(); // <9> persistentCacheManager.close(); transactionManager.shutdown(); // end::testXACacheWithThreeTiers[] }
Example #9
Source File: XAGettingStarted.java From ehcache3 with Apache License 2.0 | 5 votes |
@Test @SuppressWarnings("unchecked") public void testXACacheWithWriteThrough() throws Exception { // tag::testXACacheWithWriteThrough[] BitronixTransactionManager transactionManager = TransactionManagerServices.getTransactionManager(); // <1> Class<CacheLoaderWriter<?, ?>> klazz = (Class<CacheLoaderWriter<?, ?>>) (Class) (SampleLoaderWriter.class); CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder() .using(new LookupTransactionManagerProviderConfiguration(BitronixTransactionManagerLookup.class)) // <2> .withCache("xaCache", CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, // <3> ResourcePoolsBuilder.heap(10)) // <4> .withService(new XAStoreConfiguration("xaCache")) // <5> .withService(new DefaultCacheLoaderWriterConfiguration(klazz, singletonMap(1L, "eins"))) // <6> .build() ) .build(true); Cache<Long, String> xaCache = cacheManager.getCache("xaCache", Long.class, String.class); transactionManager.begin(); // <7> { assertThat(xaCache.get(1L), equalTo("eins")); // <8> xaCache.put(1L, "one"); // <9> } transactionManager.commit(); // <10> cacheManager.close(); transactionManager.shutdown(); // end::testXACacheWithWriteThrough[] }
Example #10
Source File: XAGettingStarted.java From ehcache3 with Apache License 2.0 | 5 votes |
@Test public void testNonTransactionalAccess() throws Exception { // tag::testNonTransactionalAccess[] BitronixTransactionManager transactionManager = TransactionManagerServices.getTransactionManager(); // <1> CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder() .using(new LookupTransactionManagerProviderConfiguration(BitronixTransactionManagerLookup.class)) // <2> .withCache("xaCache", CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, // <3> ResourcePoolsBuilder.heap(10)) // <4> .withService(new XAStoreConfiguration("xaCache")) // <5> .build() ) .build(true); Cache<Long, String> xaCache = cacheManager.getCache("xaCache", Long.class, String.class); try { xaCache.get(1L); // <6> fail("expected XACacheException"); } catch (XACacheException e) { // expected } cacheManager.close(); transactionManager.shutdown(); // end::testNonTransactionalAccess[] }
Example #11
Source File: XAGettingStarted.java From ehcache3 with Apache License 2.0 | 5 votes |
@Test public void testSimpleXACache() throws Exception { // tag::testSimpleXACache[] BitronixTransactionManager transactionManager = TransactionManagerServices.getTransactionManager(); // <1> CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder() .using(new LookupTransactionManagerProviderConfiguration(BitronixTransactionManagerLookup.class)) // <2> .withCache("xaCache", CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, // <3> ResourcePoolsBuilder.heap(10)) // <4> .withService(new XAStoreConfiguration("xaCache")) // <5> .build() ) .build(true); Cache<Long, String> xaCache = cacheManager.getCache("xaCache", Long.class, String.class); transactionManager.begin(); // <6> { xaCache.put(1L, "one"); // <7> } transactionManager.commit(); // <8> cacheManager.close(); transactionManager.shutdown(); // end::testSimpleXACache[] }
Example #12
Source File: BitronixTransactionManagerLookup.java From ehcache3 with Apache License 2.0 | 5 votes |
@Override public TransactionManagerWrapper lookupTransactionManagerWrapper() { // <2> if (!TransactionManagerServices.isTransactionManagerRunning()) { // <3> throw new IllegalStateException("BTM must be started beforehand"); } TransactionManagerWrapper tmWrapper = new TransactionManagerWrapper(TransactionManagerServices.getTransactionManager(), new BitronixXAResourceRegistry()); // <4> LOGGER.info("Using looked up transaction manager : {}", tmWrapper); return tmWrapper; }
Example #13
Source File: CreateUserServlet.java From genericconnector with Apache License 2.0 | 5 votes |
@Override public void contextDestroyed(ServletContextEvent sce) { TransactionConfigurator.unregisterMicroserviceResourceFactory("xa/bookingService"); TransactionConfigurator.unregisterMicroserviceResourceFactory("xa/letterService"); //dont do this here - see note in #contextInitialized TransactionManagerServices.getTransactionManager().shutdown(); }
Example #14
Source File: XACacheTest.java From ehcache3 with Apache License 2.0 | 5 votes |
@After public void tearDownBtm() throws Exception { if(cacheManager != null) { cacheManager.close(); } if (TransactionManagerServices.isTransactionManagerRunning()) { TransactionManagerServices.getTransactionManager().shutdown(); } }
Example #15
Source File: XACacheTest.java From ehcache3 with Apache License 2.0 | 5 votes |
private void initTransactionManagerServices() { TransactionManagerServices.getConfiguration() .setLogPart1Filename(new File(getStoragePath(), "btm1.tlog").getAbsolutePath()) .setLogPart2Filename(new File(getStoragePath(), "btm2.tlog").getAbsolutePath()) .setServerId("XACacheTest") .setGracefulShutdownInterval(0); }
Example #16
Source File: XACacheTest.java From ehcache3 with Apache License 2.0 | 5 votes |
@Before public void setUpBtmConfig() throws Exception { storagePath = folder.newFolder(); initTransactionManagerServices(); transactionManager = TransactionManagerServices.getTransactionManager(); }
Example #17
Source File: AbstractJTATransactionManagerConfiguration.java From high-performance-java-persistence with Apache License 2.0 | 5 votes |
@Bean public bitronix.tm.Configuration btmConfig() { bitronix.tm.Configuration configuration = TransactionManagerServices.getConfiguration(); if (!TransactionManagerServices.isTransactionManagerRunning()) { configuration.setServerId("spring-btm"); configuration.setWarnAboutZeroResourceTransaction(true); configuration.setJournal(btmJournal); } return configuration; }
Example #18
Source File: JTATransactionManagerConfiguration.java From high-performance-java-persistence with Apache License 2.0 | 5 votes |
@Bean public bitronix.tm.Configuration btmConfig() { bitronix.tm.Configuration configuration = TransactionManagerServices.getConfiguration(); if (!TransactionManagerServices.isTransactionManagerRunning()) { configuration.setServerId("spring-btm"); configuration.setWarnAboutZeroResourceTransaction(true); configuration.setJournal(btmJournal); } return configuration; }
Example #19
Source File: MicroserviceResourceProducerTest.java From genericconnector with Apache License 2.0 | 5 votes |
@Test public void testGetTransactionAssistant() throws ResourceException, NotSupportedException, SystemException { MicroserviceResourceFactory msrFactory = mock(MicroserviceResourceFactory.class); MicroserviceXAResource xa = new MicroserviceXAResource("a", null); when(msrFactory.build()).thenReturn(xa); MicroserviceResourceProducer.registerMicroserviceResourceFactory("a", msrFactory); MicroserviceResourceProducer producer = MicroserviceResourceProducer.getProducers().values().iterator().next(); BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager(); try{ tm.begin(); //TEST TransactionAssistant ta = producer.getTransactionAssistant(); assertNotNull(ta); //check its enlisted in TX assertEquals(1, TransactionContextHelper.currentTransaction().getEnlistedResourcesUniqueNames().size()); assertEquals("a", TransactionContextHelper.currentTransaction().getEnlistedResourcesUniqueNames().iterator().next()); //TEST ta.close(); //cannot check its delisted from TX, because that happens during deconstruction of the transaction, becuase the TX is a global one //close also removed it from the holders - so check its gone assertNull(producer.findXAResourceHolder(xa)); }finally{ tm.rollback(); } }
Example #20
Source File: XACacheTest.java From ehcache3 with Apache License 2.0 | 4 votes |
@Test public void testRecoveryAfterCrash() throws Exception { CacheConfigurationBuilder<Long, String> cacheConfigurationBuilder = CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, newResourcePoolsBuilder() .heap(10, EntryUnit.ENTRIES) .offheap(10, MemoryUnit.MB) .disk(20, MemoryUnit.MB, true)); cacheManager = CacheManagerBuilder.newCacheManagerBuilder() .with(new CacheManagerPersistenceConfiguration(getStoragePath())) .withCache("txCache1", cacheConfigurationBuilder.withService(new XAStoreConfiguration("txCache1")).build()) .withCache("txCache2", cacheConfigurationBuilder.withService(new XAStoreConfiguration("txCache2")).build()) .using(new LookupTransactionManagerProviderConfiguration(BitronixTransactionManagerLookup.class)) .build(true); Cache<Long, String> txCache1 = cacheManager.getCache("txCache1", Long.class, String.class); Cache<Long, String> txCache2 = cacheManager.getCache("txCache2", Long.class, String.class); transactionManager.begin(); { txCache1.put(1L, "one"); txCache2.put(1L, "un"); } transactionManager.getCurrentTransaction().addTransactionStatusChangeListener((oldStatus, newStatus) -> { if (newStatus == Status.STATUS_COMMITTING) { throw new AbortError(); } }); try { transactionManager.commit(); fail("expected AbortError"); } catch (AbortError e) { // expected } cacheManager.close(); txCache1 = null; txCache2 = null; transactionManager.shutdown(); initTransactionManagerServices(); transactionManager = TransactionManagerServices.getTransactionManager(); cacheManager.init(); txCache1 = cacheManager.getCache("txCache1", Long.class, String.class); txCache2 = cacheManager.getCache("txCache2", Long.class, String.class); transactionManager.begin(); { assertThat(txCache1.get(1L), equalTo("one")); assertThat(txCache2.get(1L), equalTo("un")); } transactionManager.commit(); }
Example #21
Source File: XA107Test.java From ehcache3 with Apache License 2.0 | 4 votes |
@After public void tearDown() throws Exception { if (TransactionManagerServices.isTransactionManagerRunning()) { TransactionManagerServices.getTransactionManager().shutdown(); } }
Example #22
Source File: XAGettingStarted.java From ehcache3 with Apache License 2.0 | 4 votes |
@Before public void setUp() throws Exception { TransactionManagerServices.getConfiguration().setJournal("null").setServerId(getClass().getSimpleName()); }
Example #23
Source File: XAGettingStarted.java From ehcache3 with Apache License 2.0 | 4 votes |
@After public void tearDown() throws Exception { if (TransactionManagerServices.isTransactionManagerRunning()) { TransactionManagerServices.getTransactionManager().shutdown(); } }
Example #24
Source File: XA107Test.java From ehcache3 with Apache License 2.0 | 4 votes |
@Before public void setUp() throws Exception { TransactionManagerServices.getConfiguration().setJournal("null").setServerId(getClass().getSimpleName()); }
Example #25
Source File: TransactionalOsgiTest.java From ehcache3 with Apache License 2.0 | 4 votes |
@After public void tearDown() throws Exception { if (TransactionManagerServices.isTransactionManagerRunning()) { TransactionManagerServices.getTransactionManager().shutdown(); } }
Example #26
Source File: TransactionalOsgiTest.java From ehcache3 with Apache License 2.0 | 4 votes |
@Before public void setUp() throws Exception { TransactionManagerServices.getConfiguration().setJournal("null").setServerId(getClass().getSimpleName()); }
Example #27
Source File: AbstractJTATransactionManagerConfiguration.java From high-performance-java-persistence with Apache License 2.0 | 4 votes |
@Bean(destroyMethod = "shutdown") @DependsOn(value = "btmConfig") public BitronixTransactionManager jtaTransactionManager() { return TransactionManagerServices.getTransactionManager(); }
Example #28
Source File: StatefulSerializerTest.java From ehcache3 with Apache License 2.0 | 4 votes |
@Before public void setUp() throws Exception { TransactionManagerServices.getConfiguration().setJournal("null").setServerId(getClass().getSimpleName()); }
Example #29
Source File: StatefulSerializerTest.java From ehcache3 with Apache License 2.0 | 4 votes |
@After public void tearDown() throws Exception { if (TransactionManagerServices.isTransactionManagerRunning()) { TransactionManagerServices.getTransactionManager().shutdown(); } }
Example #30
Source File: JTATransactionManagerConfiguration.java From high-performance-java-persistence with Apache License 2.0 | 4 votes |
@Bean(destroyMethod = "shutdown") @DependsOn(value = "btmConfig") public BitronixTransactionManager jtaTransactionManager() { return TransactionManagerServices.getTransactionManager(); }