CacheServiceTest: avoid NegativeArraySizeException

If there is more than Integer.MAX_VALUE free memory available, the
byte[] allocation in the freeMem method will overflow to a negative
number and cause NegativeArraySizeException to be thrown.

This is now safeguarded against so that when the array size is
determined, it's capped at Integer.MAX_VALUE.

Caught by ctrueden.