@Override public void signalReady() { if (signalManager != null) { signalManager.signalReady(getConstraints()); } }
@Test public void testSignalDirectoryCreatedOnSignal() throws IOException { SignalManager manager = new SignalManager(fileSystem, testDirectory); Assert.assertFalse("Signal directory shouldn't exist before signals", fileSystem.exists(testDirectory)); Constraints constraints = new Constraints(DatasetTestUtilities.USER_SCHEMA). with("email", "signalCreatesDir@domain.com"); manager.signalReady(constraints); Assert.assertTrue("Signal directory created on signals", fileSystem.exists(testDirectory)); }
@Test public void testConstraintsSignaledReady() throws IOException { SignalManager manager = new SignalManager(fileSystem, testDirectory); Constraints constraints = new Constraints(DatasetTestUtilities.USER_SCHEMA). with("email", "testConstraintsSignaledReady@domain.com"); manager.signalReady(constraints); String normalizedConstraints = SignalManager.getNormalizedConstraints(constraints); Assert.assertTrue(this.fileSystem.exists(new Path(this.testDirectory, normalizedConstraints))); }
@Test public void testConstraintsSignaledReadyPreviouslySignaled() throws IOException, InterruptedException { SignalManager manager = new SignalManager(fileSystem, testDirectory); Constraints constraints = new Constraints(DatasetTestUtilities.USER_SCHEMA) .with("email", "testConstraintsSignaledReadyPreviouslySignaled@domain.com"); String normalizedConstraints = SignalManager.getNormalizedConstraints(constraints); Path signalFilePath = new Path(this.testDirectory,normalizedConstraints); manager.signalReady(constraints); Assert.assertTrue(this.fileSystem.exists(signalFilePath)); long firstSignalContents = this.fileSystem.getFileStatus(signalFilePath).getModificationTime(); // the modified time depends on the filesystem, and may only be granular to the second // signal and check until the modified time is after the current time, or until // enough time has past that the signal should have been distinguishable long spinStart = System.currentTimeMillis(); long signaledTime = 0; while(firstSignalContents >= signaledTime && (System.currentTimeMillis() - spinStart) <= 2000) { manager.signalReady(constraints); signaledTime = manager.getReadyTimestamp(constraints); } Assert.assertFalse("Second signal should not match the first", signaledTime == firstSignalContents); }
@Test public void testMultiConstraintsSignaledReady() throws IOException { SignalManager manager = new SignalManager(fileSystem, testDirectory); Constraints constraints = new Constraints(DatasetTestUtilities.USER_SCHEMA). with("email", "kiteuser@domain.com").with("username", "kiteuser"); manager.signalReady(constraints); String normalizedConstraints = SignalManager.getNormalizedConstraints(constraints); Assert.assertTrue(this.fileSystem.exists(new Path(this.testDirectory, normalizedConstraints))); }