Untitled
unknown
plain_text
a month ago
1.7 kB
8
Indexable
public class MultiCloudCacheTest {
public static void main(String[] args) {
System.out.println("Starting Multi-Cloud Cache Test...\n");
// Initialize Cache with a capacity of 2 documents
DocumentCache cache = new DocumentCache(2);
cache.storeDocument(10, 500); // Stored Doc 10 (Size 500). Fetch count: 1
cache.storeDocument(20, 600); // Stored Doc 20 (Size 600). Fetch count: 1
System.out.println("Test 1 (Fetch Doc 10): " + cache.fetchDocument(10) + " \t| Expected: 500");
// Doc 10 fetch count is now 2
// Cache is full (holding Doc 10 and Doc 20). Storing new document!
// Doc 20 has fetch count 1. Doc 10 has fetch count 2. Doc 20 should be evicted.
cache.storeDocument(30, 700);
System.out.println("Test 2 (Fetch Doc 20): " + cache.fetchDocument(20) + " \t| Expected: -1");
System.out.println("Test 3 (Fetch Doc 30): " + cache.fetchDocument(30) + " \t| Expected: 700");
// Doc 30 fetch count is now 2
// Cache is full (holding Doc 10 and Doc 30). Both have fetch count 2.
// Storing new document! Tie-breaker needed.
// Doc 10 was fetched longest time ago. Doc 10 should be evicted.
cache.storeDocument(40, 800);
System.out.println("Test 4 (Fetch Doc 10): " + cache.fetchDocument(10) + " \t| Expected: -1");
System.out.println("Test 5 (Fetch Doc 30): " + cache.fetchDocument(30) + " \t| Expected: 700");
System.out.println("Test 6 (Fetch Doc 40): " + cache.fetchDocument(40) + " \t| Expected: 800");
System.out.println("\nTest Complete.");
}
}Editor is loading...
Leave a Comment