com.google.appengine.api.datastore.DatastoreServiceConfig Java Examples
The following examples show how to use
com.google.appengine.api.datastore.DatastoreServiceConfig.
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: ObjectifyService.java From nomulus with Apache License 2.0 | 6 votes |
/** * Performs static initialization for Objectify to register types and do other setup. * * <p>This method is non-idempotent, so it should only be called exactly once, which is achieved * by calling it from this class's static initializer block. */ private static void initOfyOnce() { // Set an ObjectifyFactory that uses our extended ObjectifyImpl. // The "false" argument means that we are not using the v5-style Objectify embedded entities. com.googlecode.objectify.ObjectifyService.setFactory(new ObjectifyFactory(false) { @Override public Objectify begin() { return new SessionKeyExposingObjectify(this); } @Override protected AsyncDatastoreService createRawAsyncDatastoreService(DatastoreServiceConfig cfg) { // In the unit test environment, wrap the Datastore service in a proxy that can be used to // examine the number of requests sent to Datastore. AsyncDatastoreService service = super.createRawAsyncDatastoreService(cfg); return RegistryEnvironment.get().equals(RegistryEnvironment.UNITTEST) ? new RequestCapturingAsyncDatastoreService(service) : service; }}); // Translators must be registered before any entities can be registered. registerTranslators(); registerEntityClasses(EntityClasses.ALL_CLASSES); }
Example #2
Source File: ReadPolicyTest.java From java-docs-samples with Apache License 2.0 | 6 votes |
@Test public void readPolicy_strong_returnsAllResults() { double deadline = 5.0; ReadPolicy policy = new ReadPolicy(ReadPolicy.Consistency.STRONG); DatastoreServiceConfig datastoreConfig = DatastoreServiceConfig.Builder.withReadPolicy(policy).deadline(deadline); DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(datastoreConfig); Entity parent = new Entity("Person", "a"); Entity child = new Entity("Person", "b", parent.getKey()); datastore.put(ImmutableList.<Entity>of(parent, child)); Query q = new Query("Person").setAncestor(parent.getKey()); List<Entity> results = datastore.prepare(q).asList(FetchOptions.Builder.withDefaults()); assertWithMessage("query results").that(results).hasSize(2); }
Example #3
Source File: ConfigTest.java From appengine-tck with Apache License 2.0 | 6 votes |
@Test public void testConfigBuilder() { DatastoreServiceConfig config = DatastoreServiceConfig.Builder.withDefaults(); assertEquals(new ReadPolicy(Consistency.STRONG).getConsistency(), config.getReadPolicy().getConsistency()); config = DatastoreServiceConfig.Builder.withDeadline(10); assertEquals(new Double(10), config.getDeadline()); config.deadline(20); assertEquals(new Double(20), config.getDeadline()); config = DatastoreServiceConfig.Builder.withImplicitTransactionManagementPolicy(ImplicitTransactionManagementPolicy.AUTO); assertEquals(ImplicitTransactionManagementPolicy.AUTO, config.getImplicitTransactionManagementPolicy()); config.implicitTransactionManagementPolicy(ImplicitTransactionManagementPolicy.NONE); assertEquals(ImplicitTransactionManagementPolicy.NONE, config.getImplicitTransactionManagementPolicy()); config = DatastoreServiceConfig.Builder.withMaxEntityGroupsPerRpc(5); assertEquals(new Integer(5), config.getMaxEntityGroupsPerRpc()); config.maxEntityGroupsPerRpc(2); assertEquals(new Integer(2), config.getMaxEntityGroupsPerRpc()); config = DatastoreServiceConfig.Builder.withReadPolicy(new ReadPolicy(Consistency.EVENTUAL)); assertEquals(new ReadPolicy(Consistency.EVENTUAL).getConsistency(), config.getReadPolicy().getConsistency()); config.readPolicy(new ReadPolicy(Consistency.STRONG)); assertEquals(new ReadPolicy(Consistency.STRONG).getConsistency(), config.getReadPolicy().getConsistency()); }
Example #4
Source File: ReadPolicyTest.java From java-docs-samples with Apache License 2.0 | 5 votes |
@Test public void readPolicy_eventual_returnsNoResults() { // [START data_consistency] double deadline = 5.0; // Construct a read policy for eventual consistency ReadPolicy policy = new ReadPolicy(ReadPolicy.Consistency.EVENTUAL); // Set the read policy DatastoreServiceConfig eventuallyConsistentConfig = DatastoreServiceConfig.Builder.withReadPolicy(policy); // Set the call deadline DatastoreServiceConfig deadlineConfig = DatastoreServiceConfig.Builder.withDeadline(deadline); // Set both the read policy and the call deadline DatastoreServiceConfig datastoreConfig = DatastoreServiceConfig.Builder.withReadPolicy(policy).deadline(deadline); // Get Datastore service with the given configuration DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(datastoreConfig); // [END data_consistency] Entity parent = new Entity("Person", "a"); Entity child = new Entity("Person", "b", parent.getKey()); datastore.put(ImmutableList.<Entity>of(parent, child)); // Even though we are using an ancestor query, the policy is set to // eventual, so we should get eventually-consistent results. Since the // local data store test config is set to 100% unapplied jobs, there // should be no results. Query q = new Query("Person").setAncestor(parent.getKey()); List<Entity> results = datastore.prepare(q).asList(FetchOptions.Builder.withDefaults()); assertWithMessage("query results").that(results).isEmpty(); }
Example #5
Source File: DatastoreConfigPrintingServlet.java From appengine-java-vm-runtime with Apache License 2.0 | 5 votes |
@Override protected void doGet( HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException { PrintWriter writer = httpServletResponse.getWriter(); // Just because it's deprecated doesn't mean we don't want to test it. DatastoreConfig config = DatastoreServiceFactory.getDefaultDatastoreConfig(); writer.println(config.getImplicitTransactionManagementPolicy().name()); DatastoreServiceConfig serviceConfig = DatastoreServiceConfig.Builder.withDefaults(); writer.println(serviceConfig.getImplicitTransactionManagementPolicy().name()); writer.println(serviceConfig.getReadPolicy().getConsistency()); writer.println(serviceConfig.getDeadline()); }
Example #6
Source File: ConfigTest.java From appengine-tck with Apache License 2.0 | 5 votes |
@Test(expected = ApiDeadlineExceededException.class) public void testDeadlineConfig() { DatastoreServiceConfig config = DatastoreServiceConfig.Builder.withDeadline(0.00001); DatastoreService ds = DatastoreServiceFactory.getDatastoreService(config); assertNotNull(ds); Entity g1 = new Entity("test"); g1.setProperty("deadline", "0.00001"); ds.put(g1); }
Example #7
Source File: TxPolicyTest.java From appengine-tck with Apache License 2.0 | 5 votes |
@Test public void testAutoPolicy() throws Exception { DatastoreServiceConfig config = DatastoreServiceConfig.Builder.withImplicitTransactionManagementPolicy(ImplicitTransactionManagementPolicy.AUTO); DatastoreService ds = DatastoreServiceFactory.getDatastoreService(config); Key k1 = null; Transaction tx = ds.beginTransaction(); try { // this one should be part of auto Tx k1 = ds.put(new Entity("PutAutoTx")); } finally { tx.rollback(); } Assert.assertTrue(ds.get(Collections.singleton(k1)).isEmpty()); k1 = ds.put(new Entity("DeleteAutoTx")); try { Assert.assertNotNull(ds.get(k1)); tx = ds.beginTransaction(); try { // this one should be part of auto Tx ds.delete(k1); } finally { tx.rollback(); } Assert.assertNotNull(ds.get(k1)); } finally { ds.delete(k1); } }
Example #8
Source File: ConfigTest.java From appengine-tck with Apache License 2.0 | 4 votes |
@Test(expected = IllegalArgumentException.class) public void testTranManagePolicyAsyncInvalidConfig() { DatastoreServiceConfig config = DatastoreServiceConfig.Builder.withImplicitTransactionManagementPolicy(ImplicitTransactionManagementPolicy.AUTO); // Async Service does not support AUTO DatastoreServiceFactory.getAsyncDatastoreService(config); }