2 * Copyright 2011 Google Inc.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.google.ipc.invalidation.ticl;
19 import com.google.ipc.invalidation.common.DigestFunction;
20 import com.google.ipc.invalidation.external.client.InvalidationClient;
21 import com.google.ipc.invalidation.external.client.InvalidationListener;
22 import com.google.ipc.invalidation.external.client.SystemResources;
23 import com.google.ipc.invalidation.ticl.proto.ChannelCommon.NetworkEndpointId;
24 import com.google.ipc.invalidation.ticl.proto.ClientProtocol.ClientConfigP;
25 import com.google.ipc.invalidation.ticl.proto.ClientProtocol.ObjectIdP;
26 import com.google.ipc.invalidation.ticl.proto.ClientProtocol.RegistrationSummary;
27 import com.google.ipc.invalidation.util.Bytes;
28 import com.google.ipc.invalidation.util.InternalBase;
29 import com.google.ipc.invalidation.util.Preconditions;
30 import com.google.ipc.invalidation.util.TextBuilder;
32 import java.util.ArrayList;
33 import java.util.Collection;
37 * An interface that exposes some extra methods for testing an invalidation client implementation.
40 public interface TestableInvalidationClient extends InvalidationClient {
42 /** The state of the registration manager exposed for testing. */
43 public class RegistrationManagerState extends InternalBase {
45 /** The registration summary of all objects registered by the client (known at the client). */
46 private final RegistrationSummary clientSummary;
48 /** The last known registration summary from the server. */
49 private final RegistrationSummary serverSummary;
51 /** The objects registered by the client (as known at the client). */
52 private final Collection<ObjectIdP> registeredObjects;
54 public RegistrationManagerState(RegistrationSummary clientSummary,
55 RegistrationSummary serverSummary, ObjectIdP[] registeredObjects) {
56 this(clientSummary, serverSummary, new ArrayList<ObjectIdP>(registeredObjects.length));
57 for (ObjectIdP registeredObject : registeredObjects) {
58 this.registeredObjects.add(registeredObject);
62 public RegistrationManagerState(RegistrationSummary clientSummary,
63 RegistrationSummary serverSummary, Collection<ObjectIdP> registeredObjects) {
64 this.clientSummary = Preconditions.checkNotNull(clientSummary);
65 this.serverSummary = Preconditions.checkNotNull(serverSummary);
66 this.registeredObjects = Preconditions.checkNotNull(registeredObjects);
69 public RegistrationSummary getClientSummary() {
73 public RegistrationSummary getServerSummary() {
77 public Collection<ObjectIdP> getRegisteredObjects() {
78 return registeredObjects;
82 public void toCompactString(TextBuilder builder) {
83 builder.append("<RegistrationManagerState: clientSummary=").append(clientSummary);
84 builder.append(", serverSummary=").append(serverSummary);
85 builder.append(", registeredObjects=<").append(registeredObjects).append(">");
89 /** Returns whether the Ticl is started. */
90 boolean isStartedForTest();
92 /** Stops the system resources. */
95 /** Returns the current time on the client. */
96 long getResourcesTimeMs();
98 /** Returns the client internal scheduler */
99 SystemResources.Scheduler getInternalSchedulerForTest();
101 /** Returns the client storage. */
102 SystemResources.Storage getStorage();
104 /** Returns a snapshot of the performance counters/statistics . */
105 Statistics getStatisticsForTest();
107 /** Returns the digest function used for computing digests for object registrations. */
108 DigestFunction getDigestFunctionForTest();
111 * Returns a copy of the registration manager's state
113 * REQUIRES: This method is called on the internal scheduler.
115 RegistrationManagerState getRegistrationManagerStateCopyForTest();
118 * Changes the existing delay for the network timeout delay in the operation scheduler to be
121 void changeNetworkTimeoutDelayForTest(int delayMs);
124 * Changes the existing delay for the heartbeat delay in the operation scheduler to be
127 void changeHeartbeatDelayForTest(int delayMs);
130 * Sets the digest store to be {@code digestStore} for testing purposes.
132 * REQUIRES: This method is called before the Ticl has been started.
134 void setDigestStoreForTest(DigestStore<ObjectIdP> digestStore);
136 /** Returns the client id that is used for squelching invalidations on the server side. */
137 byte[] getApplicationClientIdForTest();
139 /** Returns the listener that was registered by the caller. */
140 InvalidationListener getInvalidationListenerForTest();
142 /** Returns the current client token. */
143 Bytes getClientTokenForTest();
145 /** Returns the single key used to write all the Ticl state. */
146 String getClientTokenKeyForTest();
148 /** Returns the next time a message is allowed to be sent to the server (could be in the past). */
149 long getNextMessageSendTimeMsForTest();
151 /** Returns the configuration used by the client. */
152 ClientConfigP getConfigForTest();
155 * Returns the network endpoint id of the client. May throw {@code UnsupportedOperationException}.
157 NetworkEndpointId getNetworkIdForTest();