PageRenderTime 15ms CodeModel.GetById 1ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/com/google/appengine/datanucleus/jdo/JDOTransactionOptionsTest.java

http://datanucleus-appengine.googlecode.com/
Java | 80 lines | 53 code | 9 blank | 18 comment | 0 complexity | e00a3503df6a261c8097de9bcab6042f MD5 | raw file
 1/*
 2 * Copyright (C) 2010 Google Inc
 3 *
 4 * Licensed under the Apache License, Version 2.0 (the "License");
 5 * you may not use this file except in compliance with the License.
 6 * You may obtain a copy of the License at
 7 *
 8 * http://www.apache.org/licenses/LICENSE-2.0
 9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package com.google.appengine.datanucleus.jdo;
17
18import com.google.appengine.api.datastore.TransactionOptions;
19import com.google.appengine.datanucleus.DatastoreManager;
20import com.google.appengine.datanucleus.Utils;
21
22import java.util.Map;
23
24import javax.jdo.JDOHelper;
25
26/**
27 * @author Max Ross <max.ross@gmail.com>
28 */
29public class JDOTransactionOptionsTest extends JDOTestCase {
30
31  public void testDefault() {
32    DatastoreManager storeMgr = (DatastoreManager) getExecutionContext().getStoreManager();
33    TransactionOptions txnOpts = storeMgr.getDefaultDatastoreTransactionOptions();
34    assertFalse(txnOpts.isXG());
35  }
36
37  public void testIsXG_Props() {
38    pm.close();
39    pmf.close();
40    Map<String, String> props = Utils.newHashMap();
41    props.put("datanucleus.appengine.datastoreEnableXGTransactions", Boolean.TRUE.toString());
42    pmf = JDOHelper.getPersistenceManagerFactory(props, getPersistenceManagerFactoryName().name());
43    pm = pmf.getPersistenceManager();
44    DatastoreManager storeMgr = (DatastoreManager) getExecutionContext().getStoreManager();
45    TransactionOptions txnOpts = storeMgr.getDefaultDatastoreTransactionOptions();
46    assertTrue(txnOpts.isXG());
47  }
48
49  public void testIsNotXG_Props() {
50    pm.close();
51    pmf.close();
52    Map<String, String> props = Utils.newHashMap();
53    props.put("datanucleus.appengine.datastoreEnableXGTransactions", Boolean.FALSE.toString());
54    pmf = JDOHelper.getPersistenceManagerFactory(props, getPersistenceManagerFactoryName().name());
55    pm = pmf.getPersistenceManager();
56    DatastoreManager storeMgr = (DatastoreManager) getExecutionContext().getStoreManager();
57    TransactionOptions txnOpts = storeMgr.getDefaultDatastoreTransactionOptions();
58    assertFalse(txnOpts.isXG());
59  }
60
61  public void testIsXG_Config() {
62    pm.close();
63    pmf.close();
64    pmf = JDOHelper.getPersistenceManagerFactory("allowXGTxns");
65    pm = pmf.getPersistenceManager();
66    DatastoreManager storeMgr = (DatastoreManager) getExecutionContext().getStoreManager();
67    TransactionOptions txnOpts = storeMgr.getDefaultDatastoreTransactionOptions();
68    assertTrue(txnOpts.isXG());
69  }
70
71  public void testIsNotXG_Config() {
72    pm.close();
73    pmf.close();
74    pmf = JDOHelper.getPersistenceManagerFactory("disallowXGTxns");
75    pm = pmf.getPersistenceManager();
76    DatastoreManager storeMgr = (DatastoreManager) getExecutionContext().getStoreManager();
77    TransactionOptions txnOpts = storeMgr.getDefaultDatastoreTransactionOptions();
78    assertFalse(txnOpts.isXG());
79  }
80}