<commit_before>/*
 */

package com.googlecode.objectify.test.util;

import java.util.logging.Logger;

import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.EntityNotFoundException;
import com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig;
import com.google.appengine.tools.development.testing.LocalMemcacheServiceTestConfig;
import com.google.appengine.tools.development.testing.LocalServiceTestHelper;
import com.google.appengine.tools.development.testing.LocalTaskQueueTestConfig;
import com.googlecode.objectify.Key;
import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyFilter;
import com.googlecode.objectify.ObjectifyService;
import com.googlecode.objectify.Ref;

/**
 * All tests should extend this class to set up the GAE environment.
 * @see <a href="http://code.google.com/appengine/docs/java/howto/unittesting.html">Unit Testing in Appengine</a>
 *
 * @author <NAME> <<EMAIL>>
 */
public class TestBase
{
	/** */
	@SuppressWarnings("unused")
	private static Logger log = Logger.getLogger(TestBase.class.getName());

	/** */
	protected TestObjectifyFactory fact;

	/** */
	private final LocalServiceTestHelper helper =
			new LocalServiceTestHelper(
					// Our tests assume strong consistency
					new LocalDatastoreServiceTestConfig(),//.setDefaultHighRepJobPolicyUnappliedJobPercentage(100),
					new LocalMemcacheServiceTestConfig(),
					new LocalTaskQueueTestConfig());
	/** */
	@BeforeMethod
	public void setUp()
	{
		this.helper.setUp();
		this.fact = new TestObjectifyFactory();
		ObjectifyService.setFactory(this.fact);	// just in case
	}

	/** */
	@AfterMethod
	public void tearDown()
	{
		// This is normally done in ObjectifyFilter but that doesn't exist for tests
		ObjectifyFilter.complete();

		this.helper.tearDown();
	}

	/** Utility methods that puts, clears the session, and immediately gets an entity */
	protected <T> T putClearGet(T saveMe)
	{
		Objectify ofy = this.fact.begin();

		Key<T> key = ofy.save().entity(saveMe).now();

		try
		{
			Entity ent = ds().get(null, key.getRaw());
			System.out.println(ent);
		}
		catch (EntityNotFoundException e) { throw new RuntimeException(e); }

		ofy.clear();

		return ofy.load().key(key).get();
	}

	/** Get a DatastoreService */
	protected DatastoreService ds()
	{
		return DatastoreServiceFactory.getDatastoreService();
	}

	/** Useful utility method */
	protected void assertRefUninitialzied(Ref<?> ref) {
		try {
			ref.get();
			assert false;
		} catch (IllegalStateException ex) {}
	}

}
<commit_msg>Missing file for better way to enable HRD in tests checkin<commit_after>/*
 */

package com.googlecode.objectify.test.util;

import java.util.logging.Logger;

import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.EntityNotFoundException;
import com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig;
import com.google.appengine.tools.development.testing.LocalMemcacheServiceTestConfig;
import com.google.appengine.tools.development.testing.LocalServiceTestHelper;
import com.google.appengine.tools.development.testing.LocalTaskQueueTestConfig;
import com.googlecode.objectify.Key;
import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyFilter;
import com.googlecode.objectify.Ref;

/**
 * All tests should extend this class to set up the GAE environment.
 * @see <a href="http://code.google.com/appengine/docs/java/howto/unittesting.html">Unit Testing in Appengine</a>
 *
 * @author <NAME> <<EMAIL>>
 */
public class TestBase
{
	/** */
	@SuppressWarnings("unused")
	private static Logger log = Logger.getLogger(TestBase.class.getName());

	/** */
	protected TestObjectifyFactory fact;

	/** */
	private final LocalServiceTestHelper helper =
			new LocalServiceTestHelper(
					// Our tests assume strong consistency
					new LocalDatastoreServiceTestConfig().setAlternateHighRepJobPolicyClass(AlwaysApplyJobPolicy.class),
					new LocalMemcacheServiceTestConfig(),
					new LocalTaskQueueTestConfig());
	/** */
	@BeforeMethod
	public void setUp()
	{
		this.helper.setUp();
		this.fact = TestObjectifyService.factory();
	}

	/** */
	@AfterMethod
	public void tearDown()
	{
		// This is normally done in ObjectifyFilter but that doesn't exist for tests
		ObjectifyFilter.complete();

		this.helper.tearDown();
	}

	/** Utility methods that puts, clears the session, and immediately gets an entity */
	protected <T> T putClearGet(T saveMe)
	{
		Objectify ofy = this.fact.begin();

		Key<T> key = ofy.save().entity(saveMe).now();

		try
		{
			Entity ent = ds().get(null, key.getRaw());
			System.out.println(ent);
		}
		catch (EntityNotFoundException e) { throw new RuntimeException(e); }

		ofy.clear();

		return ofy.load().key(key).get();
	}

	/** Get a DatastoreService */
	protected DatastoreService ds()
	{
		return DatastoreServiceFactory.getDatastoreService();
	}

	/** Useful utility method */
	protected void assertRefUninitialzied(Ref<?> ref) {
		try {
			ref.get();
			assert false;
		} catch (IllegalStateException ex) {}
	}

}

{'fraction_non_alphanumeric': 0.11672473867595819, 'fraction_numerical': 0.0005226480836236934, 'mean_word_length': 3.9491379310344827, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '373574', 'n_tokens_mistral': 1879, 'n_tokens_neox': 1731, 'n_words': 353}