import java.util.concurrent.*;
public class InventoryTest {
public static void main(String[] args) throws Exception {
InventoryManager inventory = new InMemoryInventoryManager();
inventory.addStock("P1", 10);
ExecutorService executor = Executors.newFixedThreadPool(2);
Callable<Boolean> t1 = () -> inventory.reserve("P1", 6);
Callable<Boolean> t2 = () -> inventory.reserve("P1", 6);
Future<Boolean> f1 = executor.submit(t1);
Future<Boolean> f2 = executor.submit(t2);
boolean r1 = f1.get();
boolean r2 = f2.get();
assert r1 ^ r2; // only one should succeed
assert inventory.getAvailableStock("P1") == 4;
// Release test
inventory.release("P1", 2);
assert inventory.getAvailableStock("P1") == 6;
executor.shutdown();
System.out.println("✅ Inventory tests passed");
}
}