Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / cacheinvalidation / src / java / com / google / ipc / invalidation / ticl / TestableInvalidationClient.java
1 /*
2  * Copyright 2011 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
17 package com.google.ipc.invalidation.ticl;
18
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;
31
32 import java.util.ArrayList;
33 import java.util.Collection;
34
35
36 /**
37  * An interface that exposes some extra methods for testing an invalidation client implementation.
38  *
39  */
40 public interface TestableInvalidationClient extends InvalidationClient {
41
42   /** The state of the registration manager exposed for testing. */
43   public class RegistrationManagerState extends InternalBase {
44
45     /** The registration summary of all objects registered by the client (known at the client). */
46     private final RegistrationSummary clientSummary;
47
48     /** The last known registration summary from the server. */
49     private final RegistrationSummary serverSummary;
50
51     /** The objects registered by the client (as known at the client). */
52     private final Collection<ObjectIdP> registeredObjects;
53
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);
59       }
60     }
61
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);
67     }
68
69     public RegistrationSummary getClientSummary() {
70       return clientSummary;
71     }
72
73     public RegistrationSummary getServerSummary() {
74       return serverSummary;
75     }
76
77     public Collection<ObjectIdP> getRegisteredObjects() {
78       return registeredObjects;
79     }
80
81     @Override
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(">");
86     }
87   }
88
89   /** Returns whether the Ticl is started. */
90   boolean isStartedForTest();
91
92   /** Stops the system resources. */
93   void stopResources();
94
95   /** Returns the current time on the client. */
96   long getResourcesTimeMs();
97
98   /** Returns the client internal scheduler */
99   SystemResources.Scheduler getInternalSchedulerForTest();
100
101   /** Returns the client storage. */
102   SystemResources.Storage getStorage();
103
104   /** Returns a snapshot of the performance counters/statistics . */
105   Statistics getStatisticsForTest();
106
107   /** Returns the digest function used for computing digests for object registrations. */
108   DigestFunction getDigestFunctionForTest();
109
110   /**
111    * Returns a copy of the registration manager's state
112    * <p>
113    * REQUIRES: This method is called on the internal scheduler.
114    */
115   RegistrationManagerState getRegistrationManagerStateCopyForTest();
116
117   /**
118    * Changes the existing delay for the network timeout delay in the operation scheduler to be
119    * {@code delayMs}.
120    */
121   void changeNetworkTimeoutDelayForTest(int delayMs);
122
123   /**
124    * Changes the existing delay for the heartbeat delay in the operation scheduler to be
125    * {@code delayMs}.
126    */
127   void changeHeartbeatDelayForTest(int delayMs);
128
129   /**
130    * Sets the digest store to be {@code digestStore} for testing purposes.
131    * <p>
132    * REQUIRES: This method is called before the Ticl has been started.
133    */
134   void setDigestStoreForTest(DigestStore<ObjectIdP> digestStore);
135
136   /** Returns the client id that is used for squelching invalidations on the server side. */
137   byte[] getApplicationClientIdForTest();
138
139   /** Returns the listener that was registered by the caller. */
140   InvalidationListener getInvalidationListenerForTest();
141
142   /** Returns the current client token. */
143   Bytes getClientTokenForTest();
144
145   /** Returns the single key used to write all the Ticl state. */
146   String getClientTokenKeyForTest();
147
148   /** Returns the next time a message is allowed to be sent to the server (could be in the past). */
149   long getNextMessageSendTimeMsForTest();
150
151   /** Returns the configuration used by the client. */
152   ClientConfigP getConfigForTest();
153
154   /**
155    * Returns the network endpoint id of the client. May throw {@code UnsupportedOperationException}.
156    */
157   NetworkEndpointId getNetworkIdForTest();
158 }