}
});
// prime the pump by getting the first avail synchronously
System.out.println("~~~AVAILABILITY PROXY CALL #" + 0 + " at " + new Date());
AvailabilityType firstAvail = ap.getAvailability();
assert UP.equals(firstAvail) : "Can't even get our first avail correctly: " + firstAvail;
Mockito.when(resourceContainer.getAvailability()).thenReturn(
new Availability(new Resource(1), AvailabilityType.UP)); // last avail is UP and will stay as UP
// make several calls to availProxy.getAvailability() in quick succession
final int numCalls = 15;
final Hashtable<String, AvailabilityType> availResults = new Hashtable<String, AvailabilityType>(numCalls);
final Hashtable<String, Date> dateResults = new Hashtable<String, Date>(numCalls);
final Hashtable<String, Throwable> throwableResults = new Hashtable<String, Throwable>(numCalls);
// this will count how many times the proxy actually calls the facet (i.e. component's) getAvail method
numberOfFacetCalls.set(0);
// release the hounds!
for (int i = 1; i <= numCalls; i++) {
try {
// space out the calls slightly to allow some async invocations to complete, giving us a mix of
// sync and async completions
try {
Thread.sleep(25);
} catch (InterruptedException e) {
//
}
System.out.println("~~~AVAILABILITY PROXY CALL #" + i + " at " + new Date());
AvailabilityType availCheck = ap.getAvailability();
// if the avail check is in progress, defer to our last known avail (which should be UP, due to
// our first call, and the simulating mock)
availCheck = (availCheck == AvailabilityType.UNKNOWN) ? resourceContainer.getAvailability()
.getAvailabilityType() : availCheck;
availResults.put("Call-" + i, availCheck);