PageRenderTime 26ms CodeModel.GetById 9ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

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