/tests/com/google/appengine/datanucleus/query/NoQueryDelegate.java

http://datanucleus-appengine.googlecode.com/ · Java · 73 lines · 39 code · 10 blank · 24 comment · 4 complexity · 22a2721288595e68f8f5fbaaf8a7c6ff 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. */
  16. package com.google.appengine.datanucleus.query;
  17. import com.google.appengine.api.datastore.dev.LocalDatastoreService;
  18. import com.google.apphosting.api.ApiProxy;
  19. import java.util.List;
  20. import java.util.concurrent.Future;
  21. /**
  22. * A delegate that throws a {@link RuntimeException} whenever RunQuery is
  23. * invoked on the datastore service.
  24. *
  25. * @author Max Ross <max.ross@gmail.com>
  26. */
  27. public class NoQueryDelegate implements ApiProxy.Delegate {
  28. private ApiProxy.Delegate original;
  29. public byte[] makeSyncCall(ApiProxy.Environment environment, String pkg, String method, byte[] bytes)
  30. throws ApiProxy.ApiProxyException {
  31. if (pkg.equals(LocalDatastoreService.PACKAGE) && method.equals("RunQuery")) {
  32. throw new RuntimeException("boom");
  33. }
  34. return original.makeSyncCall(environment, pkg, method, bytes);
  35. }
  36. public Future makeAsyncCall(ApiProxy.Environment environment, String pkg, String method, byte[] bytes,
  37. ApiProxy.ApiConfig apiConfig) {
  38. if (pkg.equals(LocalDatastoreService.PACKAGE) && method.equals("RunQuery")) {
  39. throw new RuntimeException("boom");
  40. }
  41. return original.makeAsyncCall(environment, pkg, method, bytes, apiConfig);
  42. }
  43. public void log(ApiProxy.Environment environment, ApiProxy.LogRecord logRecord) {
  44. original.log(environment, logRecord);
  45. }
  46. public NoQueryDelegate install() {
  47. original = ApiProxy.getDelegate();
  48. ApiProxy.setDelegate(this);
  49. // original = CloudCoverLocalServiceTestHelper.getDelegate();
  50. // CloudCoverLocalServiceTestHelper.setDelegate(this);
  51. return this;
  52. }
  53. public void flushLogs(ApiProxy.Environment environment) {
  54. original.flushLogs(environment);
  55. }
  56. public List<Thread> getRequestThreads(ApiProxy.Environment environment) {
  57. return original.getRequestThreads(environment);
  58. }
  59. public void uninstall() {
  60. ApiProxy.setDelegate(original);
  61. // CloudCoverLocalServiceTestHelper.setDelegate(original);
  62. }
  63. }