PageRenderTime 31ms CodeModel.GetById 18ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 1ms

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

http://datanucleus-appengine.googlecode.com/
Java | 106 lines | 77 code | 10 blank | 19 comment | 0 complexity | 234ffcae217c39f7699977192b58f11d 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.DatastoreServiceConfig;
 19import com.google.appengine.api.datastore.ReadPolicy;
 20import com.google.appengine.datanucleus.DatastoreManager;
 21import com.google.appengine.datanucleus.Utils;
 22
 23import java.util.Map;
 24
 25import javax.jdo.JDOFatalUserException;
 26import javax.jdo.JDOHelper;
 27
 28/**
 29 * @author Max Ross <max.ross@gmail.com>
 30 */
 31public class JDODatastoreServiceConfigTest extends JDOTestCase {
 32
 33  public void testDefaultStorageVersion() {
 34    DatastoreManager storeMgr = (DatastoreManager) getExecutionContext().getStoreManager();
 35    DatastoreServiceConfig config = storeMgr.getDefaultDatastoreServiceConfigForReads();
 36    DatastoreServiceConfig defaultConfig = DatastoreServiceConfig.Builder.withDefaults();
 37    assertEquals(defaultConfig.getDeadline(), config.getDeadline());
 38    assertEquals(defaultConfig.getReadPolicy(), config.getReadPolicy());
 39  }
 40
 41  public void testNonDefaultValuesWithStandardPropertyNames() {
 42    pm.close();
 43    pmf.close();
 44    Map<String, String> props = Utils.newHashMap();
 45    props.put("javax.jdo.option.DatastoreReadTimeoutMillis", "334");
 46    props.put("javax.jdo.option.DatastoreWriteTimeoutMillis", "335");
 47    props.put(DatastoreManager.DATASTORE_READ_CONSISTENCY_PROPERTY, ReadPolicy.Consistency.EVENTUAL.name());
 48    pmf = JDOHelper.getPersistenceManagerFactory(props, getPersistenceManagerFactoryName().name());
 49    pm = pmf.getPersistenceManager();
 50    DatastoreManager storeMgr = (DatastoreManager) getExecutionContext().getStoreManager();
 51    DatastoreServiceConfig config = storeMgr.getDefaultDatastoreServiceConfigForReads();
 52    assertEquals(.334d, config.getDeadline());
 53    assertEquals(new ReadPolicy(ReadPolicy.Consistency.EVENTUAL), config.getReadPolicy());
 54    config = storeMgr.getDefaultDatastoreServiceConfigForWrites();
 55    assertEquals(.335d, config.getDeadline());
 56    assertEquals(new ReadPolicy(ReadPolicy.Consistency.EVENTUAL), config.getReadPolicy());
 57  }
 58
 59  public void testNonDefaultValuesWithDataNucPropertyNames() {
 60    pm.close();
 61    pmf.close();
 62    Map<String, String> props = Utils.newHashMap();
 63    props.put("datanucleus.datastoreReadTimeout", "334");
 64    props.put("datanucleus.datastoreWriteTimeout", "335");
 65    props.put(DatastoreManager.DATASTORE_READ_CONSISTENCY_PROPERTY, ReadPolicy.Consistency.EVENTUAL.name());
 66    pmf = JDOHelper.getPersistenceManagerFactory(props, getPersistenceManagerFactoryName().name());
 67    pm = pmf.getPersistenceManager();
 68    DatastoreManager storeMgr = (DatastoreManager) getExecutionContext().getStoreManager();
 69    DatastoreServiceConfig config = storeMgr.getDefaultDatastoreServiceConfigForReads();
 70    assertEquals(.334d, config.getDeadline());
 71    assertEquals(new ReadPolicy(ReadPolicy.Consistency.EVENTUAL), config.getReadPolicy());
 72    config = storeMgr.getDefaultDatastoreServiceConfigForWrites();
 73    assertEquals(.335d, config.getDeadline());
 74    assertEquals(new ReadPolicy(ReadPolicy.Consistency.EVENTUAL), config.getReadPolicy());
 75  }
 76
 77  public void testNonDefaultValuesInConfigFile() {
 78    pm.close();
 79    pmf.close();
 80
 81    pmf = JDOHelper.getPersistenceManagerFactory("datastoreserviceconfigprops");
 82    pm = pmf.getPersistenceManager();
 83    DatastoreManager storeMgr = (DatastoreManager) getExecutionContext().getStoreManager();
 84    DatastoreServiceConfig config = storeMgr.getDefaultDatastoreServiceConfigForReads();
 85    assertEquals(5.0d, config.getDeadline());
 86    assertEquals(new ReadPolicy(ReadPolicy.Consistency.EVENTUAL), config.getReadPolicy());
 87    config = storeMgr.getDefaultDatastoreServiceConfigForWrites();
 88    assertEquals(10.0d, config.getDeadline());
 89    assertEquals(new ReadPolicy(ReadPolicy.Consistency.EVENTUAL), config.getReadPolicy());
 90    pm.close();
 91    pmf.close();
 92  }
 93
 94  public void testUnknownReadPolicy() {
 95    pm.close();
 96    pmf.close();
 97    Map<String, String> props = Utils.newHashMap();
 98    props.put(DatastoreManager.DATASTORE_READ_CONSISTENCY_PROPERTY, "dne");
 99    try {
100      pmf = JDOHelper.getPersistenceManagerFactory(props, getPersistenceManagerFactoryName().name());
101    } catch (JDOFatalUserException e) {
102      // good
103      assertTrue(e.getCause().getMessage().startsWith("Illegal value for"));
104    }
105  }
106}