Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Open Networking Laboratory |
| 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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.intent; |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 17 | |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 18 | import static org.onosproject.net.NetTestTools.createPath; |
| 19 | import static org.onosproject.net.NetTestTools.did; |
| 20 | import static org.onosproject.net.NetTestTools.link; |
Jonathan Hart | 936c49d | 2014-10-23 16:38:59 -0700 | [diff] [blame] | 21 | |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 22 | import java.util.ArrayList; |
| 23 | import java.util.Arrays; |
Ray Milkey | 8d3ce43 | 2014-11-07 16:21:10 -0800 | [diff] [blame] | 24 | import java.util.Collection; |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 25 | import java.util.Collections; |
| 26 | import java.util.HashSet; |
Ray Milkey | 8d3ce43 | 2014-11-07 16:21:10 -0800 | [diff] [blame] | 27 | import java.util.LinkedList; |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 28 | import java.util.List; |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 29 | import java.util.Objects; |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 30 | import java.util.Set; |
Ray Milkey | 5a7787a | 2015-02-23 11:44:30 -0800 | [diff] [blame] | 31 | import java.util.concurrent.atomic.AtomicLong; |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 32 | |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 33 | import org.onosproject.core.DefaultGroupId; |
| 34 | import org.onosproject.core.GroupId; |
| 35 | import org.onosproject.net.DeviceId; |
| 36 | import org.onosproject.net.ElementId; |
| 37 | import org.onosproject.net.Link; |
Ray Milkey | 5a7787a | 2015-02-23 11:44:30 -0800 | [diff] [blame] | 38 | import org.onosproject.net.NetTestTools; |
Ray Milkey | 43a2822 | 2015-02-23 13:57:58 -0800 | [diff] [blame] | 39 | import org.onosproject.net.NetworkResource; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 40 | import org.onosproject.net.Path; |
| 41 | import org.onosproject.net.flow.FlowId; |
| 42 | import org.onosproject.net.flow.FlowRule; |
| 43 | import org.onosproject.net.flow.TrafficSelector; |
| 44 | import org.onosproject.net.flow.TrafficTreatment; |
| 45 | import org.onosproject.net.flow.criteria.Criterion; |
| 46 | import org.onosproject.net.flow.criteria.Criterion.Type; |
| 47 | import org.onosproject.net.flow.instructions.Instruction; |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame^] | 48 | import org.onosproject.net.flow.instructions.Instructions; |
Ray Milkey | cf590df | 2015-02-23 17:43:24 -0800 | [diff] [blame] | 49 | import org.onosproject.net.resource.Bandwidth; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 50 | import org.onosproject.net.resource.BandwidthResourceRequest; |
Ray Milkey | b1b66d3 | 2015-03-02 10:27:11 -0800 | [diff] [blame] | 51 | import org.onosproject.net.resource.Lambda; |
| 52 | import org.onosproject.net.resource.LambdaResourceAllocation; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 53 | import org.onosproject.net.resource.LambdaResourceRequest; |
| 54 | import org.onosproject.net.resource.LinkResourceAllocations; |
| 55 | import org.onosproject.net.resource.LinkResourceListener; |
| 56 | import org.onosproject.net.resource.LinkResourceRequest; |
| 57 | import org.onosproject.net.resource.LinkResourceService; |
Ray Milkey | bb32048 | 2015-02-25 15:16:46 -0800 | [diff] [blame] | 58 | import org.onosproject.net.resource.MplsLabel; |
| 59 | import org.onosproject.net.resource.MplsLabelResourceAllocation; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 60 | import org.onosproject.net.resource.ResourceAllocation; |
| 61 | import org.onosproject.net.resource.ResourceRequest; |
| 62 | import org.onosproject.net.resource.ResourceType; |
| 63 | import org.onosproject.net.topology.DefaultTopologyEdge; |
| 64 | import org.onosproject.net.topology.DefaultTopologyVertex; |
| 65 | import org.onosproject.net.topology.LinkWeight; |
| 66 | import org.onosproject.net.topology.PathService; |
| 67 | import org.onosproject.net.topology.TopologyVertex; |
Ray Milkey | 5a7787a | 2015-02-23 11:44:30 -0800 | [diff] [blame] | 68 | import org.onosproject.store.Timestamp; |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 69 | |
Ray Milkey | 43a2822 | 2015-02-23 13:57:58 -0800 | [diff] [blame] | 70 | import com.google.common.base.MoreObjects; |
Ray Milkey | bb32048 | 2015-02-25 15:16:46 -0800 | [diff] [blame] | 71 | import com.google.common.collect.ImmutableSet; |
Ray Milkey | 43a2822 | 2015-02-23 13:57:58 -0800 | [diff] [blame] | 72 | |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 73 | /** |
| 74 | * Common mocks used by the intent framework tests. |
| 75 | */ |
| 76 | public class IntentTestsMocks { |
| 77 | /** |
| 78 | * Mock traffic selector class used for satisfying API requirements. |
| 79 | */ |
| 80 | public static class MockSelector implements TrafficSelector { |
| 81 | @Override |
| 82 | public Set<Criterion> criteria() { |
| 83 | return new HashSet<>(); |
| 84 | } |
Jonathan Hart | 936c49d | 2014-10-23 16:38:59 -0700 | [diff] [blame] | 85 | |
| 86 | @Override |
| 87 | public Criterion getCriterion(Type type) { |
| 88 | return null; |
| 89 | } |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Mock traffic treatment class used for satisfying API requirements. |
| 94 | */ |
| 95 | public static class MockTreatment implements TrafficTreatment { |
| 96 | @Override |
| 97 | public List<Instruction> instructions() { |
Ayaka Koshibe | b1224ab | 2015-01-31 00:48:58 +0000 | [diff] [blame] | 98 | return new ArrayList<>(); |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 99 | } |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame^] | 100 | |
| 101 | @Override |
| 102 | public List<Instruction> deferred() { |
| 103 | return null; |
| 104 | } |
| 105 | |
| 106 | @Override |
| 107 | public List<Instruction> immediate() { |
| 108 | return null; |
| 109 | } |
| 110 | |
| 111 | @Override |
| 112 | public Instructions.TableTypeTransition tableTransition() { |
| 113 | return null; |
| 114 | } |
| 115 | |
| 116 | @Override |
| 117 | public Boolean clearedDeferred() { |
| 118 | return null; |
| 119 | } |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Mock path service for creating paths within the test. |
| 124 | */ |
| 125 | public static class MockPathService implements PathService { |
| 126 | |
| 127 | final String[] pathHops; |
| 128 | final String[] reversePathHops; |
| 129 | |
| 130 | /** |
| 131 | * Constructor that provides a set of hops to mock. |
| 132 | * |
| 133 | * @param pathHops path hops to mock |
| 134 | */ |
| 135 | public MockPathService(String[] pathHops) { |
| 136 | this.pathHops = pathHops; |
| 137 | String[] reversed = pathHops.clone(); |
| 138 | Collections.reverse(Arrays.asList(reversed)); |
| 139 | reversePathHops = reversed; |
| 140 | } |
| 141 | |
| 142 | @Override |
| 143 | public Set<Path> getPaths(ElementId src, ElementId dst) { |
| 144 | Set<Path> result = new HashSet<>(); |
| 145 | |
| 146 | String[] allHops = new String[pathHops.length]; |
| 147 | |
| 148 | if (src.toString().endsWith(pathHops[0])) { |
| 149 | System.arraycopy(pathHops, 0, allHops, 0, pathHops.length); |
| 150 | } else { |
| 151 | System.arraycopy(reversePathHops, 0, allHops, 0, pathHops.length); |
| 152 | } |
| 153 | |
| 154 | result.add(createPath(allHops)); |
| 155 | return result; |
| 156 | } |
| 157 | |
| 158 | @Override |
| 159 | public Set<Path> getPaths(ElementId src, ElementId dst, LinkWeight weight) { |
Ray Milkey | 8d3ce43 | 2014-11-07 16:21:10 -0800 | [diff] [blame] | 160 | final Set<Path> paths = getPaths(src, dst); |
| 161 | |
| 162 | for (Path path : paths) { |
| 163 | final DeviceId srcDevice = path.src().deviceId(); |
| 164 | final DeviceId dstDevice = path.dst().deviceId(); |
| 165 | final TopologyVertex srcVertex = new DefaultTopologyVertex(srcDevice); |
| 166 | final TopologyVertex dstVertex = new DefaultTopologyVertex(dstDevice); |
| 167 | final Link link = link(src.toString(), 1, dst.toString(), 1); |
| 168 | |
| 169 | final double weightValue = weight.weight(new DefaultTopologyEdge(srcVertex, dstVertex, link)); |
| 170 | if (weightValue < 0) { |
| 171 | return new HashSet<>(); |
| 172 | } |
| 173 | } |
| 174 | return paths; |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 175 | } |
| 176 | } |
Ray Milkey | 8d3ce43 | 2014-11-07 16:21:10 -0800 | [diff] [blame] | 177 | |
| 178 | public static class MockLinkResourceAllocations implements LinkResourceAllocations { |
| 179 | @Override |
| 180 | public Set<ResourceAllocation> getResourceAllocation(Link link) { |
Ray Milkey | b1b66d3 | 2015-03-02 10:27:11 -0800 | [diff] [blame] | 181 | return ImmutableSet.of( |
| 182 | new LambdaResourceAllocation(Lambda.valueOf(77)), |
| 183 | new MplsLabelResourceAllocation(MplsLabel.valueOf(10))); |
Ray Milkey | 8d3ce43 | 2014-11-07 16:21:10 -0800 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | @Override |
| 187 | public IntentId intendId() { |
| 188 | return null; |
| 189 | } |
| 190 | |
| 191 | @Override |
| 192 | public Collection<Link> links() { |
| 193 | return null; |
| 194 | } |
| 195 | |
| 196 | @Override |
| 197 | public Set<ResourceRequest> resources() { |
| 198 | return null; |
| 199 | } |
| 200 | |
| 201 | @Override |
| 202 | public ResourceType type() { |
| 203 | return null; |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | public static class MockedAllocationFailure extends RuntimeException { } |
| 208 | |
| 209 | public static class MockResourceService implements LinkResourceService { |
| 210 | |
| 211 | double availableBandwidth = -1.0; |
| 212 | int availableLambda = -1; |
| 213 | |
| 214 | /** |
| 215 | * Allocates a resource service that will allow bandwidth allocations |
| 216 | * up to a limit. |
| 217 | * |
| 218 | * @param bandwidth available bandwidth limit |
| 219 | * @return resource manager for bandwidth requests |
| 220 | */ |
| 221 | public static MockResourceService makeBandwidthResourceService(double bandwidth) { |
| 222 | final MockResourceService result = new MockResourceService(); |
| 223 | result.availableBandwidth = bandwidth; |
| 224 | return result; |
| 225 | } |
| 226 | |
| 227 | /** |
| 228 | * Allocates a resource service that will allow lambda allocations. |
| 229 | * |
| 230 | * @param lambda Lambda to return for allocation requests. Currently unused |
| 231 | * @return resource manager for lambda requests |
| 232 | */ |
| 233 | public static MockResourceService makeLambdaResourceService(int lambda) { |
| 234 | final MockResourceService result = new MockResourceService(); |
| 235 | result.availableLambda = lambda; |
| 236 | return result; |
| 237 | } |
| 238 | |
| 239 | public void setAvailableBandwidth(double availableBandwidth) { |
| 240 | this.availableBandwidth = availableBandwidth; |
| 241 | } |
| 242 | |
| 243 | public void setAvailableLambda(int availableLambda) { |
| 244 | this.availableLambda = availableLambda; |
| 245 | } |
| 246 | |
| 247 | |
| 248 | @Override |
| 249 | public LinkResourceAllocations requestResources(LinkResourceRequest req) { |
| 250 | int lambda = -1; |
| 251 | double bandwidth = -1.0; |
| 252 | |
| 253 | for (ResourceRequest resourceRequest : req.resources()) { |
| 254 | if (resourceRequest.type() == ResourceType.BANDWIDTH) { |
| 255 | final BandwidthResourceRequest brr = (BandwidthResourceRequest) resourceRequest; |
| 256 | bandwidth = brr.bandwidth().toDouble(); |
| 257 | } else if (resourceRequest.type() == ResourceType.LAMBDA) { |
| 258 | lambda = 1; |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | if (availableBandwidth < bandwidth) { |
| 263 | throw new MockedAllocationFailure(); |
| 264 | } |
| 265 | if (lambda > 0 && availableLambda == 0) { |
| 266 | throw new MockedAllocationFailure(); |
| 267 | } |
| 268 | |
| 269 | return new IntentTestsMocks.MockLinkResourceAllocations(); |
| 270 | } |
| 271 | |
| 272 | @Override |
| 273 | public void releaseResources(LinkResourceAllocations allocations) { |
| 274 | // Mock |
| 275 | } |
| 276 | |
| 277 | @Override |
| 278 | public LinkResourceAllocations updateResources(LinkResourceRequest req, |
| 279 | LinkResourceAllocations oldAllocations) { |
| 280 | return null; |
| 281 | } |
| 282 | |
| 283 | @Override |
| 284 | public Iterable<LinkResourceAllocations> getAllocations() { |
Ray Milkey | bb32048 | 2015-02-25 15:16:46 -0800 | [diff] [blame] | 285 | return ImmutableSet.of( |
| 286 | new IntentTestsMocks.MockLinkResourceAllocations()); |
Ray Milkey | 8d3ce43 | 2014-11-07 16:21:10 -0800 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | @Override |
| 290 | public Iterable<LinkResourceAllocations> getAllocations(Link link) { |
Ray Milkey | bb32048 | 2015-02-25 15:16:46 -0800 | [diff] [blame] | 291 | return ImmutableSet.of( |
| 292 | new IntentTestsMocks.MockLinkResourceAllocations()); |
Ray Milkey | 8d3ce43 | 2014-11-07 16:21:10 -0800 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | @Override |
| 296 | public LinkResourceAllocations getAllocations(IntentId intentId) { |
Ray Milkey | bb32048 | 2015-02-25 15:16:46 -0800 | [diff] [blame] | 297 | return new IntentTestsMocks.MockLinkResourceAllocations(); |
Ray Milkey | 8d3ce43 | 2014-11-07 16:21:10 -0800 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | @Override |
| 301 | public Iterable<ResourceRequest> getAvailableResources(Link link) { |
| 302 | final List<ResourceRequest> result = new LinkedList<>(); |
| 303 | if (availableBandwidth > 0.0) { |
Ray Milkey | cf590df | 2015-02-23 17:43:24 -0800 | [diff] [blame] | 304 | result.add(new BandwidthResourceRequest( |
| 305 | Bandwidth.bps(availableBandwidth))); |
Ray Milkey | 8d3ce43 | 2014-11-07 16:21:10 -0800 | [diff] [blame] | 306 | } |
| 307 | if (availableLambda > 0) { |
| 308 | result.add(new LambdaResourceRequest()); |
| 309 | } |
| 310 | return result; |
| 311 | } |
| 312 | |
| 313 | @Override |
weibit | 00c94f5 | 2014-11-16 07:09:05 -0800 | [diff] [blame] | 314 | public Iterable<ResourceRequest> getAvailableResources(Link link, LinkResourceAllocations allocations) { |
Ray Milkey | 8d3ce43 | 2014-11-07 16:21:10 -0800 | [diff] [blame] | 315 | return null; |
| 316 | } |
Ray Milkey | e97ede9 | 2014-11-20 10:43:12 -0800 | [diff] [blame] | 317 | |
| 318 | @Override |
| 319 | public void addListener(LinkResourceListener listener) { |
| 320 | |
| 321 | } |
| 322 | |
| 323 | @Override |
| 324 | public void removeListener(LinkResourceListener listener) { |
| 325 | |
| 326 | } |
Ray Milkey | 8d3ce43 | 2014-11-07 16:21:10 -0800 | [diff] [blame] | 327 | } |
| 328 | |
Ray Milkey | 930fc66 | 2014-11-11 16:07:45 -0800 | [diff] [blame] | 329 | private static final IntentTestsMocks.MockSelector SELECTOR = |
| 330 | new IntentTestsMocks.MockSelector(); |
| 331 | private static final IntentTestsMocks.MockTreatment TREATMENT = |
| 332 | new IntentTestsMocks.MockTreatment(); |
| 333 | |
| 334 | public static class MockFlowRule implements FlowRule { |
| 335 | |
| 336 | int priority; |
sangho | 11c30ac | 2015-01-22 14:30:55 -0800 | [diff] [blame] | 337 | Type type; |
| 338 | |
Ray Milkey | 930fc66 | 2014-11-11 16:07:45 -0800 | [diff] [blame] | 339 | public MockFlowRule(int priority) { |
| 340 | this.priority = priority; |
sangho | 11c30ac | 2015-01-22 14:30:55 -0800 | [diff] [blame] | 341 | this.type = Type.DEFAULT; |
Ray Milkey | 930fc66 | 2014-11-11 16:07:45 -0800 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | @Override |
| 345 | public FlowId id() { |
| 346 | return FlowId.valueOf(1); |
| 347 | } |
| 348 | |
| 349 | @Override |
| 350 | public short appId() { |
| 351 | return 0; |
| 352 | } |
| 353 | |
| 354 | @Override |
Sho SHIMIZU | 75a5bd9 | 2014-11-25 11:22:56 -0800 | [diff] [blame] | 355 | public GroupId groupId() { |
| 356 | return new DefaultGroupId(0); |
alshabib | 28204e5 | 2014-11-12 18:29:45 -0800 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | @Override |
Ray Milkey | 930fc66 | 2014-11-11 16:07:45 -0800 | [diff] [blame] | 360 | public int priority() { |
| 361 | return priority; |
| 362 | } |
| 363 | |
| 364 | @Override |
| 365 | public DeviceId deviceId() { |
| 366 | return did("1"); |
| 367 | } |
| 368 | |
| 369 | @Override |
| 370 | public TrafficSelector selector() { |
| 371 | return SELECTOR; |
| 372 | } |
| 373 | |
| 374 | @Override |
| 375 | public TrafficTreatment treatment() { |
| 376 | return TREATMENT; |
| 377 | } |
| 378 | |
| 379 | @Override |
| 380 | public int timeout() { |
| 381 | return 0; |
| 382 | } |
| 383 | |
| 384 | @Override |
| 385 | public boolean isPermanent() { |
| 386 | return false; |
| 387 | } |
| 388 | |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 389 | @Override |
| 390 | public int hashCode() { |
| 391 | return Objects.hash(priority); |
| 392 | } |
Ray Milkey | 930fc66 | 2014-11-11 16:07:45 -0800 | [diff] [blame] | 393 | |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 394 | @Override |
| 395 | public boolean equals(Object obj) { |
| 396 | if (this == obj) { |
| 397 | return true; |
| 398 | } |
| 399 | if (obj == null || getClass() != obj.getClass()) { |
| 400 | return false; |
| 401 | } |
| 402 | final MockFlowRule other = (MockFlowRule) obj; |
| 403 | return Objects.equals(this.priority, other.priority); |
| 404 | } |
sangho | 11c30ac | 2015-01-22 14:30:55 -0800 | [diff] [blame] | 405 | |
| 406 | @Override |
| 407 | public Type type() { |
| 408 | return type; |
| 409 | } |
Ray Milkey | 930fc66 | 2014-11-11 16:07:45 -0800 | [diff] [blame] | 410 | } |
| 411 | |
Ray Milkey | 5a7787a | 2015-02-23 11:44:30 -0800 | [diff] [blame] | 412 | public static class MockIntent extends Intent { |
| 413 | private static AtomicLong counter = new AtomicLong(0); |
| 414 | |
| 415 | private final Long number; |
| 416 | |
| 417 | public MockIntent(Long number) { |
| 418 | super(NetTestTools.APP_ID, Collections.emptyList()); |
| 419 | this.number = number; |
| 420 | } |
| 421 | |
Ray Milkey | 43a2822 | 2015-02-23 13:57:58 -0800 | [diff] [blame] | 422 | public MockIntent(Long number, Collection<NetworkResource> resources) { |
| 423 | super(NetTestTools.APP_ID, resources); |
| 424 | this.number = number; |
| 425 | } |
| 426 | |
Ray Milkey | 5a7787a | 2015-02-23 11:44:30 -0800 | [diff] [blame] | 427 | public Long number() { |
| 428 | return number; |
| 429 | } |
| 430 | |
| 431 | public static Long nextId() { |
| 432 | return counter.getAndIncrement(); |
| 433 | } |
Ray Milkey | 43a2822 | 2015-02-23 13:57:58 -0800 | [diff] [blame] | 434 | |
| 435 | @Override |
| 436 | public String toString() { |
| 437 | return MoreObjects.toStringHelper(getClass()) |
| 438 | .add("id", id()) |
| 439 | .add("appId", appId()) |
| 440 | .toString(); |
| 441 | } |
Ray Milkey | 5a7787a | 2015-02-23 11:44:30 -0800 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | public static class MockTimestamp implements Timestamp { |
| 445 | final int value; |
| 446 | |
| 447 | public MockTimestamp(int value) { |
| 448 | this.value = value; |
| 449 | } |
| 450 | |
| 451 | @Override |
| 452 | public int compareTo(Timestamp o) { |
| 453 | if (!(o instanceof MockTimestamp)) { |
| 454 | return -1; |
| 455 | } |
| 456 | MockTimestamp that = (MockTimestamp) o; |
| 457 | return (this.value > that.value ? -1 : (this.value == that.value ? 0 : 1)); |
| 458 | } |
| 459 | } |
| 460 | |
Ray Milkey | 930fc66 | 2014-11-11 16:07:45 -0800 | [diff] [blame] | 461 | |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 462 | } |