void setHooks() throws IOException { touch(); spawnTouchLoop(); }
public Lockfile(File filename) { this.lockFile = filename; this.touchFrequency = getIntProperty(TOUCH_FREQUENCY_PROPERTY, DEFAULT_TOUCH_FREQUENCY); this.sleepTimeBeforeLastModifiedCheck = getIntProperty(SLEEP_TIME_FOR_LAST_MODIFIED_CHECK_PROPERTY, DEFAULT_SLEEP_TIME_FOR_LAST_MODIFIED_CHECK); }
public boolean isChecksumEquals(String expectedSignature) { return matchChecksum(getLocalFile(), expectedSignature); }
@Test public void shouldConnectToAnSSLServerWithSelfSignedCertWhenInsecureModeIsNoVerifyHost() throws Exception { ServerBinaryDownloader downloader = new ServerBinaryDownloader(ServerUrlGeneratorMother.generatorFor("localhost", server.getPort()), new File("testdata/test_cert.pem"), SslVerificationMode.NO_VERIFY_HOST); downloader.download(DownloadableFile.AGENT); assertThat(DownloadableFile.AGENT.getLocalFile().exists(), is(true)); }
private void cleanupAgentPluginsFile() throws IOException { FileUtils.deleteQuietly(AGENT_PLUGINS.getLocalFile()); }
@Test public void shouldDownloadLauncherJarIfLocalCopyIsStale() throws IOException { //because new invocation will take care of pulling latest agent down, and will then operate on it with the latest launcher -jj File staleJar = randomFile(AGENT_LAUNCHER_JAR); long original = staleJar.length(); new AgentLauncherImpl().launch(launchDescriptor()); assertThat(staleJar.length(), not(original)); }
@Test public void shouldGetExtraPropertiesFromHeader() { assertExtraProperties("", new HashMap<>()); assertExtraProperties("Key1=Value1 key2=value2", new HashMap<String, String>() {{ put("Key1", "Value1"); put("key2", "value2"); }}); assertExtraProperties("Key1=Value1 key2=value2 key2=value3", new HashMap<String, String>() {{ put("Key1", "Value1"); put("key2", "value2"); }}); assertExtraProperties("Key1%20WithSpace=Value1%20WithSpace key2=value2", new HashMap<String, String>() {{ put("Key1 WithSpace", "Value1 WithSpace"); put("key2", "value2"); }}); }
public synchronized void delete() { requestTouchLoopToStop(); waitForTouchLoopThread(); try { deleteLockFile(); } catch (Exception e) { LOG.error("Error deleting lock file at {}", lockFile.getAbsolutePath(), e); } }
boolean exists() { return lockFile.exists() && lockFileChangedWithinMinutes(10); }
private Thread registerShutdownHook() { Thread shutdownHook = new Thread(() -> lockFile.delete()); Runtime.getRuntime().addShutdownHook(shutdownHook); return shutdownHook; }
@Before public void setUp() throws IOException { cleanup(); }
public AgentLauncherImpl() { this(new AgentJarBasedAgentParentRunner()); }
boolean lockFileChangedWithinMinutes(int minutes) { sleepForSomeTime(); // prevents race condition where the file was just created and not modified. long changedAgo = System.currentTimeMillis() - lockFile.lastModified(); return changedAgo < minutes * 60 * 1000; }
public int launch(AgentLaunchDescriptor descriptor) { LogConfigurator logConfigurator = new LogConfigurator("agent-launcher-logback.xml"); return logConfigurator.runWithLogger(() -> doLaunch(descriptor)); }
@Test public void shouldNotFailIfExtraPropertiesAreNotFormattedProperly() { assertExtraProperties("abc", new HashMap<>()); }
private SetupOfAgentPluginsFile setupAgentsPluginFile() throws IOException { return new SetupOfAgentPluginsFile(AGENT_PLUGINS.getLocalFile()); }
@Test public void shouldDownloadLauncherJarIfLocalCopyIsStale_butShouldReturnWithoutDownloadingOrLaunchingAgent() throws Exception { File launcher = randomFile(AGENT_LAUNCHER_JAR); long original = launcher.length(); File agentFile = randomFile(AGENT_BINARY_JAR); long originalAgentLength = agentFile.length(); new AgentLauncherImpl().launch(launchDescriptor()); assertThat(launcher.length(), not(original)); assertThat(agentFile.length(), is(originalAgentLength)); }
@After public void tearDown() { cleanup(); }