Java Code Examples for com.google.apphosting.api.ApiProxy#getDelegate()

The following examples show how to use com.google.apphosting.api.ApiProxy#getDelegate() . 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: SessionManagerTest.java    From appengine-java-vm-runtime with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
 public void testDatastoreTimeouts() throws EntityNotFoundException {
   Delegate original = ApiProxy.getDelegate();
   // Throw in a couple of datastore timeouts
   TimeoutGeneratingDelegate newDelegate = new TimeoutGeneratingDelegate(original);
   try {
     ApiProxy.setDelegate(newDelegate);

     HttpServletRequest request = makeMockRequest(true);
        replay(request);
AppEngineSession session = manager.newSession(request);
     session.setAttribute("foo", "bar");
     newDelegate.setTimeouts(3);
     session.save();
     assertEquals(newDelegate.getTimeoutsRemaining(), 0);

     memcache.clearAll();
     manager =
         new SessionManager(Collections.<SessionStore>singletonList(new DatastoreSessionStore()));
     HttpSession session2 = manager.getSession(session.getId());
     assertEquals(session.getId(), session2.getId());
     assertEquals("bar", session2.getAttribute("foo"));
   } finally {
     ApiProxy.setDelegate(original);
   }
 }
 
Example 2
Source File: GcsServiceFactory.java    From appengine-gcs-client with Apache License 2.0 6 votes vote down vote up
static RawGcsService createRawGcsService(Map<String, String> headers) {
  ImmutableSet.Builder<HTTPHeader> builder = ImmutableSet.builder();
  if (headers != null) {
    for (Map.Entry<String, String> header : headers.entrySet()) {
      builder.add(new HTTPHeader(header.getKey(), header.getValue()));
    }
  }

  RawGcsService rawGcsService;
  Value location = SystemProperty.environment.value();
  if (location == SystemProperty.Environment.Value.Production || hasCustomAccessTokenProvider()) {
    rawGcsService = OauthRawGcsServiceFactory.createOauthRawGcsService(builder.build());
  } else if (location == SystemProperty.Environment.Value.Development) {
    rawGcsService = LocalRawGcsServiceFactory.createLocalRawGcsService();
  } else {
    Delegate<?> delegate = ApiProxy.getDelegate();
    if (delegate == null
        || delegate.getClass().getName().startsWith("com.google.appengine.tools.development")) {
      rawGcsService = LocalRawGcsServiceFactory.createLocalRawGcsService();
    } else {
      rawGcsService = OauthRawGcsServiceFactory.createOauthRawGcsService(builder.build());
    }
  }
  return rawGcsService;
}
 
Example 3
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 4
Source File: LocalRawGcsService.java    From appengine-gcs-client with Apache License 2.0 5 votes vote down vote up
private static BlobStorageAdapter getInstance() throws IOException {
  Delegate<?> apiProxyDelegate = ApiProxy.getDelegate();
  if (instance == null || instance.apiProxyDelegate != apiProxyDelegate) {
    try {
      instance = new BlobStorageAdapter(apiProxyDelegate);
    } catch (Exception e) {
      throw new IOException(e);
    }
  }
  return instance;
}
 
Example 5
Source File: LogTest.java    From appengine-java-vm-runtime with Apache License 2.0 4 votes vote down vote up
public LogRecorder() {
  oldDelegate = ApiProxy.getDelegate();
  ApiProxy.setDelegate(this);
}
 
Example 6
Source File: TestDatagramSocketServlet.java    From appengine-java-vm-runtime with Apache License 2.0 4 votes vote down vote up
/**
 * Set up a mock delegate to socket resolve calls.
 */
private ApiProxy.Delegate setUpMockDelegate() {
  ApiProxy.Delegate oldDelegate = ApiProxy.getDelegate();
  ApiProxy.setDelegate(new MockDelegate());
  return oldDelegate;
}
 
Example 7
Source File: TestSocketServlet.java    From appengine-java-vm-runtime with Apache License 2.0 4 votes vote down vote up
/**
 * Set up a mock delegate to handle resolve calls.
 */
private ApiProxy.Delegate setUpMockDelegate() {
  ApiProxy.Delegate oldDelegate = ApiProxy.getDelegate();
  ApiProxy.setDelegate(new MockDelegate());
  return oldDelegate;
}
 
Example 8
Source File: TestInetAddressServlet.java    From appengine-java-vm-runtime with Apache License 2.0 4 votes vote down vote up
/**
 * Set up a mock delegate to handle resolve calls.
 */
private ApiProxy.Delegate setUpMockDelegate() {
  ApiProxy.Delegate oldDelegate = ApiProxy.getDelegate();
  ApiProxy.setDelegate(new MockDelegate());
  return oldDelegate;
}
 
Example 9
Source File: UrlOverSocketsTestServlet.java    From appengine-java-vm-runtime with Apache License 2.0 4 votes vote down vote up
/**
 * Set up a mock delegate to handle resolve calls.
 */
private ApiProxy.Delegate setUpMockDelegate() {
  ApiProxy.Delegate oldDelegate = ApiProxy.getDelegate();
  ApiProxy.setDelegate(new UrlMockDelegate());
  return oldDelegate;
}