com.google.appengine.tools.development.testing.LocalTaskQueueTestConfig Java Examples

The following examples show how to use com.google.appengine.tools.development.testing.LocalTaskQueueTestConfig. 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: ShardedCounterServiceShardIncrementNoMemcacheTest.java    From appengine-counter with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception
{
	super.setUp();

	// See
	// http://www.ensor.cc/2010/11/unit-testing-named-queues-spring.html
	// NOTE: THE QUEUE XML PATH RELATIVE TO WEB APP ROOT, More info
	// below
	// http://stackoverflow.com/questions/11197058/testing-non-default-app-engine-task-queues
	final LocalTaskQueueTestConfig localTaskQueueConfig = new LocalTaskQueueTestConfig()
		.setDisableAutoTaskExecution(false).setQueueXmlPath("src/test/resources/queue.xml")
		.setTaskExecutionLatch(countdownLatch).setCallbackClass(DeleteShardedCounterDeferredCallback.class);

	Capability testOne = new Capability("memcache");
	CapabilityStatus testStatus = CapabilityStatus.DISABLED;
	// Initialize
	LocalCapabilitiesServiceTestConfig capabilityStatusConfig = new LocalCapabilitiesServiceTestConfig()
		.setCapabilityStatus(testOne, testStatus);

	// Use a different queue.xml for testing purposes
	helper = new LocalServiceTestHelper(
		new LocalDatastoreServiceTestConfig().setDefaultHighRepJobPolicyUnappliedJobPercentage(0.01f),
		new LocalMemcacheServiceTestConfig(), localTaskQueueConfig, capabilityStatusConfig);
	helper.setUp();
}
 
Example #2
Source File: AbstractShardedCounterServiceTest.java    From appengine-counter with Apache License 2.0 6 votes vote down vote up
protected void disableMemcache()
{
	// See
	// http://www.ensor.cc/2010/11/unit-testing-named-queues-spring.html
	// NOTE: THE QUEUE XML PATH RELATIVE TO WEB APP ROOT, More info
	// below
	// http://stackoverflow.com/questions/11197058/testing-non-default-app-engine-task-queues
	final LocalTaskQueueTestConfig localTaskQueueConfig = new LocalTaskQueueTestConfig()
		.setDisableAutoTaskExecution(false).setQueueXmlPath("src/test/resources/queue.xml")
		.setTaskExecutionLatch(countdownLatch).setCallbackClass(DeleteShardedCounterDeferredCallback.class);

	Capability testOne = new Capability("memcache");
	CapabilityStatus testStatus = CapabilityStatus.DISABLED;
	// Initialize
	LocalCapabilitiesServiceTestConfig capabilityStatusConfig = new LocalCapabilitiesServiceTestConfig()
		.setCapabilityStatus(testOne, testStatus);

	// Use a different queue.xml for testing purposes
	helper = new LocalServiceTestHelper(
		new LocalDatastoreServiceTestConfig().setDefaultHighRepJobPolicyUnappliedJobPercentage(0.01f),
		new LocalMemcacheServiceTestConfig(), localTaskQueueConfig, capabilityStatusConfig);
	helper.setUp();
}
 
Example #3
Source File: ShardedCounterServiceDeleteNoMemcacheTest.java    From appengine-counter with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception
{
	super.setUp();

	// See
	// http://www.ensor.cc/2010/11/unit-testing-named-queues-spring.html
	// NOTE: THE QUEUE XML PATH RELATIVE TO WEB APP ROOT, More info
	// below
	// http://stackoverflow.com/questions/11197058/testing-non-default-app-engine-task-queues
	final LocalTaskQueueTestConfig localTaskQueueConfig = new LocalTaskQueueTestConfig()
		.setDisableAutoTaskExecution(false).setQueueXmlPath("src/test/resources/queue.xml")
		.setTaskExecutionLatch(countdownLatch).setCallbackClass(DeleteShardedCounterDeferredCallback.class);

	Capability testOne = new Capability("memcache");
	CapabilityStatus testStatus = CapabilityStatus.DISABLED;
	// Initialize
	LocalCapabilitiesServiceTestConfig capabilityStatusConfig = new LocalCapabilitiesServiceTestConfig()
		.setCapabilityStatus(testOne, testStatus);

	// Use a different queue.xml for testing purposes
	helper = new LocalServiceTestHelper(
		new LocalDatastoreServiceTestConfig().setDefaultHighRepJobPolicyUnappliedJobPercentage(0.01f),
		new LocalMemcacheServiceTestConfig(), localTaskQueueConfig, capabilityStatusConfig);
	helper.setUp();
}
 
Example #4
Source File: ShardedCounterServiceCounterShardDecrementNoMemcacheTest.java    From appengine-counter with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception
{
	super.setUp();

	// See
	// http://www.ensor.cc/2010/11/unit-testing-named-queues-spring.html
	// NOTE: THE QUEUE XML PATH RELATIVE TO WEB APP ROOT, More info
	// below
	// http://stackoverflow.com/questions/11197058/testing-non-default-app-engine-task-queues
	final LocalTaskQueueTestConfig localTaskQueueConfig = new LocalTaskQueueTestConfig()
		.setDisableAutoTaskExecution(false).setQueueXmlPath("src/test/resources/queue.xml")
		.setTaskExecutionLatch(countdownLatch).setCallbackClass(DeleteShardedCounterDeferredCallback.class);

	Capability testOne = new Capability("memcache");
	CapabilityStatus testStatus = CapabilityStatus.DISABLED;
	// Initialize
	LocalCapabilitiesServiceTestConfig capabilityStatusConfig = new LocalCapabilitiesServiceTestConfig()
		.setCapabilityStatus(testOne, testStatus);

	// Use a different queue.xml for testing purposes
	helper = new LocalServiceTestHelper(
		new LocalDatastoreServiceTestConfig().setDefaultHighRepJobPolicyUnappliedJobPercentage(0.01f),
		new LocalMemcacheServiceTestConfig(), localTaskQueueConfig, capabilityStatusConfig);
	helper.setUp();
}
 
Example #5
Source File: GaeSimulation.java    From teammates with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Sets up the GAE simulation.
 */
public void setup() {
    synchronized (this) {
        System.out.println("Setting up GAE simulation");

        LocalTaskQueueTestConfig localTasks = new LocalTaskQueueTestConfig();
        localTasks.setQueueXmlPath(QUEUE_XML_PATH);

        LocalUserServiceTestConfig localUserServices = new LocalUserServiceTestConfig();
        LocalDatastoreServiceTestConfig localDatastore = new LocalDatastoreServiceTestConfig();
        LocalMailServiceTestConfig localMail = new LocalMailServiceTestConfig();
        LocalSearchServiceTestConfig localSearch = new LocalSearchServiceTestConfig();
        localSearch.setPersistent(false);
        LocalModulesServiceTestConfig localModules = new LocalModulesServiceTestConfig();
        LocalLogServiceTestConfig localLog = new LocalLogServiceTestConfig();
        helper = new LocalServiceTestHelper(localDatastore, localMail, localUserServices,
                                            localTasks, localSearch, localModules, localLog);

        helper.setEnvAttributes(getEnvironmentAttributesWithApplicationHostname());
        helper.setUp();
    }
}
 
Example #6
Source File: TldFanoutActionTest.java    From nomulus with Apache License 2.0 6 votes vote down vote up
@Test
public void testSuccess_returnHttpResponse() {
  run(getParamsMap("forEachRealTld", "", "endpoint", "/the/servlet"));

  List<TaskStateInfo> taskList =
      LocalTaskQueueTestConfig.getLocalTaskQueue().getQueueStateInfo().get(QUEUE).getTaskInfo();

  assertThat(taskList).hasSize(3);
  String expectedResponse = String.format(
      "OK: Launched the following 3 tasks in queue the-queue\n"
          + "- Task: '%s', tld: 'com', endpoint: '/the/servlet'\n"
          + "- Task: '%s', tld: 'net', endpoint: '/the/servlet'\n"
          + "- Task: '%s', tld: 'org', endpoint: '/the/servlet'\n",
      taskList.get(0).getTaskName(),
      taskList.get(1).getTaskName(),
      taskList.get(2).getTaskName());
  assertThat(response.getPayload()).isEqualTo(expectedResponse);
}
 
Example #7
Source File: PipelineTest.java    From appengine-pipelines with Apache License 2.0 5 votes vote down vote up
@Override
public void setUp() throws Exception {
  super.setUp();
  traceBuffer = new StringBuffer();
  helper.setUp();
  apiProxyEnvironment = ApiProxy.getCurrentEnvironment();
  System.setProperty(USE_SIMPLE_GUIDS_FOR_DEBUGGING, "true");
  taskQueue = LocalTaskQueueTestConfig.getLocalTaskQueue();
}
 
Example #8
Source File: AbstractShardedCounterServiceTest.java    From appengine-counter with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception
{
	// Don't call super.setUp because we initialize slightly differently
	// here...

	countdownLatch = new LocalTaskQueueTestConfig.TaskCountDownLatch(1);

	// See
	// http://www.ensor.cc/2010/11/unit-testing-named-queues-spring.html
	// NOTE: THE QUEUE XML PATH RELATIVE TO WEB APP ROOT, More info
	// below
	// http://stackoverflow.com/questions/11197058/testing-non-default-app-engine-task-queues
	final LocalTaskQueueTestConfig localTaskQueueConfig = new LocalTaskQueueTestConfig()
		.setDisableAutoTaskExecution(false).setQueueXmlPath("src/test/resources/queue.xml")
		.setTaskExecutionLatch(countdownLatch).setCallbackClass(DeleteShardedCounterDeferredCallback.class);

	// Use a different queue.xml for testing purposes
	helper = new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig().setApplyAllHighRepJobPolicy(),
		new LocalMemcacheServiceTestConfig(), new LocalCapabilitiesServiceTestConfig(), localTaskQueueConfig);
	helper.setUp();

	memcache = MemcacheServiceFactory.getMemcacheService();
	capabilitiesService = CapabilitiesServiceFactory.getCapabilitiesService();

	// New Objectify 5.1 Way. See https://groups.google.com/forum/#!topic/objectify-appengine/O4FHC_i7EGk
	this.session = ObjectifyService.begin();

	// Enable Joda Translators
	JodaTimeTranslators.add(ObjectifyService.factory());

	ObjectifyService.factory().register(CounterData.class);
	ObjectifyService.factory().register(CounterShardData.class);
	ObjectifyService.factory().register(CounterShardOperationData.class);

	shardedCounterServiceImpl = new ShardedCounterServiceImpl();
	this.shardedCounterService = shardedCounterServiceImpl;
}
 
Example #9
Source File: ShardedCounterServiceDeleteTest.java    From appengine-counter with Apache License 2.0 5 votes vote down vote up
/**
 * Asserts that the {@code numExpectedTasksInQueue} matches the actual number of tasks in the queue.
 */
private void assertNumTasksInQueue(int numExpectedTasksInQueue)
{
	LocalTaskQueue ltq = LocalTaskQueueTestConfig.getLocalTaskQueue();
	QueueStateInfo qsi = ltq.getQueueStateInfo()
		.get(QueueFactory.getQueue(DELETE_COUNTER_SHARD_QUEUE_NAME).getQueueName());
	assertEquals(numExpectedTasksInQueue, qsi.getTaskInfo().size());
}
 
Example #10
Source File: AppEngineTaskQueueTest.java    From appengine-pipelines with Apache License 2.0 5 votes vote down vote up
@Override
public void setUp() throws Exception {
  super.setUp();
  LocalTaskQueueTestConfig taskQueueConfig = new LocalTaskQueueTestConfig();
  taskQueueConfig.setDisableAutoTaskExecution(true);
  taskQueueConfig.setShouldCopyApiProxyEnvironment(true);
  helper = new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig(), taskQueueConfig,
      new LocalModulesServiceTestConfig());
  helper.setUp();
}
 
Example #11
Source File: PipelineTest.java    From appengine-pipelines with Apache License 2.0 5 votes vote down vote up
public PipelineTest() {
  LocalTaskQueueTestConfig taskQueueConfig = new LocalTaskQueueTestConfig();
  taskQueueConfig.setCallbackClass(TestingTaskQueueCallback.class);
  taskQueueConfig.setDisableAutoTaskExecution(false);
  taskQueueConfig.setShouldCopyApiProxyEnvironment(true);
  helper = new LocalServiceTestHelper(
      new LocalDatastoreServiceTestConfig()
          .setDefaultHighRepJobPolicyUnappliedJobPercentage(
              isHrdSafe() ? 100 : 0),
      taskQueueConfig, new LocalModulesServiceTestConfig());
}
 
Example #12
Source File: UserGuideTest.java    From appengine-pipelines with Apache License 2.0 5 votes vote down vote up
public UserGuideTest() {
  LocalTaskQueueTestConfig taskQueueConfig = new LocalTaskQueueTestConfig();
  taskQueueConfig.setCallbackClass(TestingTaskQueueCallback.class);
  taskQueueConfig.setDisableAutoTaskExecution(false);
  taskQueueConfig.setShouldCopyApiProxyEnvironment(true);
  helper = new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig(), taskQueueConfig,
      new LocalModulesServiceTestConfig());
}
 
Example #13
Source File: RetryTest.java    From appengine-pipelines with Apache License 2.0 5 votes vote down vote up
public RetryTest() {
  LocalTaskQueueTestConfig taskQueueConfig = new LocalTaskQueueTestConfig();
  taskQueueConfig.setCallbackClass(TestingTaskQueueCallback.class);
  taskQueueConfig.setDisableAutoTaskExecution(false);
  taskQueueConfig.setShouldCopyApiProxyEnvironment(true);
  helper = new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig(), taskQueueConfig,
      new LocalModulesServiceTestConfig());
}
 
Example #14
Source File: TaskQueueConfigTest.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
private void doTest() throws InterruptedException {
  // [START QueueFactory]
  QueueFactory.getQueue("my-queue-name").add(TaskOptions.Builder.withTaskName("task29"));
  // [END QueueFactory]
  // Give the task time to execute if tasks are actually enabled (which they
  // aren't, but that's part of the test).
  Thread.sleep(1000);
  LocalTaskQueue ltq = LocalTaskQueueTestConfig.getLocalTaskQueue();
  QueueStateInfo qsi =
      ltq.getQueueStateInfo().get(QueueFactory.getQueue("my-queue-name").getQueueName());
  assertEquals(1, qsi.getTaskInfo().size());
  assertEquals("task29", qsi.getTaskInfo().get(0).getTaskName());
}
 
Example #15
Source File: TaskQueueTest.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
private void doTest() throws InterruptedException {
  QueueFactory.getDefaultQueue().add(TaskOptions.Builder.withTaskName("task29"));
  // Give the task time to execute if tasks are actually enabled (which they
  // aren't, but that's part of the test).
  Thread.sleep(1000);
  LocalTaskQueue ltq = LocalTaskQueueTestConfig.getLocalTaskQueue();
  QueueStateInfo qsi = ltq.getQueueStateInfo().get(QueueFactory.getDefaultQueue().getQueueName());
  assertEquals(1, qsi.getTaskInfo().size());
  assertEquals("task29", qsi.getTaskInfo().get(0).getTaskName());
}
 
Example #16
Source File: MapreduceTestCase.java    From nomulus with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
  taskQueue = LocalTaskQueueTestConfig.getLocalTaskQueue();
  ApiProxyLocal proxy = (ApiProxyLocal) ApiProxy.getDelegate();
  // Creating files is not allowed in some test execution environments, so don't.
  proxy.setProperty(LocalBlobstoreService.NO_STORAGE_PROPERTY, "true");
  appEngineServiceUtils = new AppEngineServiceUtilsImpl(modulesService);
  when(modulesService.getVersionHostname("backend", null))
      .thenReturn("version.backend.projectid.appspot.com");
}
 
Example #17
Source File: TldFanoutActionTest.java    From nomulus with Apache License 2.0 5 votes vote down vote up
@Test
public void testSuccess_returnHttpResponse_runInEmpty() {
  run(getParamsMap("runInEmpty", "", "endpoint", "/the/servlet"));

  List<TaskStateInfo> taskList =
      LocalTaskQueueTestConfig.getLocalTaskQueue().getQueueStateInfo().get(QUEUE).getTaskInfo();

  assertThat(taskList).hasSize(1);
  String expectedResponse = String.format(
      "OK: Launched the following 1 tasks in queue the-queue\n"
          + "- Task: '%s', tld: '', endpoint: '/the/servlet'\n",
      taskList.get(0).getTaskName());
  assertThat(response.getPayload()).isEqualTo(expectedResponse);
}
 
Example #18
Source File: AppEngineRule.java    From nomulus with Apache License 2.0 4 votes vote down vote up
@Override
protected void before() throws IOException {
  setupLogging();
  temporaryFolder.create();
  Set<LocalServiceTestConfig> configs = new HashSet<>();
  if (withUrlFetch) {
    configs.add(new LocalURLFetchServiceTestConfig());
  }
  if (withDatastore) {
    configs.add(new LocalDatastoreServiceTestConfig()
        // We need to set this to allow cross entity group transactions.
        .setApplyAllHighRepJobPolicy()
        // This causes unit tests to write a file containing any indexes the test required. We
        // can use that file below to make sure we have the right indexes in our prod code.
        .setNoIndexAutoGen(false));
    // This forces app engine to write the generated indexes to a usable location.
    System.setProperty("appengine.generated.dir", temporaryFolder.getRoot().getAbsolutePath());
  }
  if (withLocalModules) {
    configs.add(new LocalModulesServiceTestConfig()
        .addBasicScalingModuleVersion("default", "1", 1)
        .addBasicScalingModuleVersion("tools", "1", 1)
        .addBasicScalingModuleVersion("backend", "1", 1));
  }
  if (withTaskQueue) {
    File queueFile = temporaryFolder.newFile("queue.xml");
    Files.asCharSink(queueFile, UTF_8).write(taskQueueXml);
    configs.add(new LocalTaskQueueTestConfig()
        .setQueueXmlPath(queueFile.getAbsolutePath()));
  }
  if (withUserService) {
    configs.add(new LocalUserServiceTestConfig());
  }

  helper = new LocalServiceTestHelper(configs.toArray(new LocalServiceTestConfig[]{}));

  if (withUserService) {
    // Set top-level properties on LocalServiceTestConfig for user login.
    helper
        .setEnvIsLoggedIn(userInfo.isLoggedIn())
        // This envAttributes thing is the only way to set userId.
        // see https://code.google.com/p/googleappengine/issues/detail?id=3579
        .setEnvAttributes(
            ImmutableMap.of(
                "com.google.appengine.api.users.UserService.user_id_key", userInfo.gaeUserId()))
        .setEnvAuthDomain(userInfo.authDomain())
        .setEnvEmail(userInfo.email())
        .setEnvIsAdmin(userInfo.isAdmin());
  }

  if (clock != null) {
    helper.setClock(() -> clock.nowUtc().getMillis());
  }

  if (withLocalModules) {
    helper.setEnvInstance("0");
  }

  helper.setUp();

  if (withDatastore) {
    ObjectifyService.initOfy();
    // Reset id allocation in ObjectifyService so that ids are deterministic in tests.
    ObjectifyService.resetNextTestId();
    if (!withoutCannedData) {
      loadInitialData();
    }
    this.ofyTestEntities.forEach(AppEngineRule::register);
  }
}
 
Example #19
Source File: AsyncHelper.java    From yawp with MIT License 3 votes vote down vote up
private static int getCountTasks() {
    LocalTaskQueue localTaskQueue = LocalTaskQueueTestConfig.getLocalTaskQueue();

    Map<String, QueueStateInfo> queueStateInfo = localTaskQueue.getQueueStateInfo();

    int count = 0;

    for (String key : queueStateInfo.keySet()) {
        count += queueStateInfo.get(key).getCountTasks();
    }

    return count;
}