private void corruptLuceneIndexFiles() throws IOException { // Corrupt lucene sandbox (delete one of the index files). File baseDir = new File(this.host.getStorageSandbox()); File luceneDir = new File(baseDir, LuceneDocumentIndexService.FILE_PATH_LUCENE); // Delete writer lock file so new host can acquire it without having to wait for // the old host to clean it up asynchronously... try { Files.delete(new File(luceneDir, "write.lock").toPath()); } catch (IOException e) { this.host.log(Level.WARNING, "Unable to delete writer.lock: %s", e.toString()); return; } Files.list(luceneDir.toPath()).forEach((Path fileP) -> { String name = fileP.toString(); this.host.log(name); if (!name.endsWith(".si") && !name.endsWith(".fdx")) { return; } try { Files.delete(fileP); } catch (Throwable e) { } }); }
private void corruptLuceneIndexFiles() throws IOException { // Corrupt lucene sandbox (delete one of the index files). File baseDir = new File(this.host.getStorageSandbox()); File luceneDir = new File(baseDir, LuceneDocumentIndexService.FILE_PATH_LUCENE); // Delete writer lock file so new host can acquire it without having to wait for // the old host to clean it up asynchronously... try { Files.delete(new File(luceneDir, "write.lock").toPath()); } catch (IOException e) { this.host.log(Level.WARNING, "Unable to delete writer.lock: %s", e.toString()); return; } Files.list(luceneDir.toPath()).forEach((Path fileP) -> { String name = fileP.toString(); this.host.log(name); if (!name.endsWith(".si") && !name.endsWith(".fdx")) { return; } try { Files.delete(fileP); } catch (Throwable e) { } }); }
@Test public void dontEscapeGivenRoot() throws IOException { // create a file in the parent of the sandbox Path fileUnderAttack = new File(this.host.getStorageSandbox()).toPath().getParent().resolve("file.txt"); Files.write(fileUnderAttack, "top secret document".getBytes(Utils.CHARSET)); FailureResponse response = this.host.getTestRequestSender() .sendAndWaitFailure(Operation.createGet(this.host, SELF_LINK + "/../file.txt")); assertEquals(Operation.STATUS_CODE_NOT_FOUND, response.op.getStatusCode()); } }
@Test public void dontEscapeGivenRoot() throws IOException { // create a file in the parent of the sandbox Path fileUnderAttack = new File(this.host.getStorageSandbox()).toPath().getParent().resolve("file.txt"); Files.write(fileUnderAttack, "top secret document".getBytes(Utils.CHARSET)); FailureResponse response = this.host.getTestRequestSender() .sendAndWaitFailure(Operation.createGet(this.host, SELF_LINK + "/../file.txt")); assertEquals(Operation.STATUS_CODE_NOT_FOUND, response.op.getStatusCode()); } }
@Before public void setup() { URI sandbox = this.host.getStorageSandbox(); this.host.log("Sandbox in %s", sandbox); DirectoryContentService dirService = new DirectoryContentService(new File(sandbox).toPath()); this.host.startService(Operation.createPost(UriUtils.buildUri(this.host, SELF_LINK)), dirService); this.host.waitForServiceAvailable(SELF_LINK); }
@Before public void setup() { URI sandbox = this.host.getStorageSandbox(); this.host.log("Sandbox in %s", sandbox); DirectoryContentService dirService = new DirectoryContentService(new File(sandbox).toPath()); this.host.startService(Operation.createPost(UriUtils.buildUri(this.host, SELF_LINK)), dirService); this.host.waitForServiceAvailable(SELF_LINK); }
assertTrue(retryStat.latestValue > 0); File storageSandbox = new File(this.host.getStorageSandbox());
@Test public void serviceCreationAndDocumentExpirationLongRunning() throws Throwable { setUpHost(false); this.host.waitForServiceAvailable(ExampleService.FACTORY_LINK); long threshold = this.host.isLongDurationTest() ? this.serviceCount : 2; LuceneDocumentIndexService.setExpiredDocumentSearchThreshold((int) threshold); Date expiration = this.host.getTestExpiration(); long opTimeoutMicros = this.host.testDurationSeconds != 0 ? this.host .getOperationTimeoutMicros() * 4 : this.host.getOperationTimeoutMicros(); this.host.setTimeoutSeconds((int) TimeUnit.MICROSECONDS.toSeconds(opTimeoutMicros)); String minimalSelfLinkPrefix = "minimal"; Service minimalFactory = this.host.startServiceAndWait( new MinimalFactoryTestService(), minimalSelfLinkPrefix, new ServiceDocument()); LuceneDocumentIndexService.setIndexFileCountThresholdForWriterRefresh(100); do { this.host.log("Expiration: %s, now: %s", expiration, new Date()); File f = new File(this.host.getStorageSandbox()); this.host.log("Disk: free %d, usable: %d, total: %d", f.getFreeSpace(), f.getUsableSpace(), f.getTotalSpace()); this.host.log("Memory: free %d, total: %d, max: %d", Runtime.getRuntime() .freeMemory(), Runtime.getRuntime().totalMemory(), Runtime.getRuntime().maxMemory()); verifyDocumentExpiration(minimalFactory); } while (this.testDurationSeconds > 0 && new Date().before(expiration)); }
assertTrue(retryStat.latestValue > 0); File storageSandbox = new File(this.host.getStorageSandbox());
@Test public void serviceCreationAndDocumentExpirationLongRunning() throws Throwable { setUpHost(false); this.host.waitForServiceAvailable(ExampleService.FACTORY_LINK); long threshold = this.host.isLongDurationTest() ? this.serviceCount : 2; LuceneDocumentIndexService.setExpiredDocumentSearchThreshold((int) threshold); Date expiration = this.host.getTestExpiration(); long opTimeoutMicros = this.host.testDurationSeconds != 0 ? this.host .getOperationTimeoutMicros() * 4 : this.host.getOperationTimeoutMicros(); this.host.setTimeoutSeconds((int) TimeUnit.MICROSECONDS.toSeconds(opTimeoutMicros)); String minimalSelfLinkPrefix = "minimal"; Service minimalFactory = this.host.startServiceAndWait( new MinimalFactoryTestService(), minimalSelfLinkPrefix, new ServiceDocument()); LuceneDocumentIndexService.setIndexFileCountThresholdForWriterRefresh(100); do { this.host.log("Expiration: %s, now: %s", expiration, new Date()); File f = new File(this.host.getStorageSandbox()); this.host.log("Disk: free %d, usable: %d, total: %d", f.getFreeSpace(), f.getUsableSpace(), f.getTotalSpace()); this.host.log("Memory: free %d, total: %d, max: %d", Runtime.getRuntime() .freeMemory(), Runtime.getRuntime().totalMemory(), Runtime.getRuntime().maxMemory()); verifyDocumentExpiration(minimalFactory); } while (this.testDurationSeconds > 0 && new Date().before(expiration)); }
File curLuceneDir = new File(new File(this.host.getStorageSandbox()), LuceneDocumentIndexService.FILE_PATH_LUCENE);
File curLuceneDir = new File(new File(this.host.getStorageSandbox()), LuceneDocumentIndexService.FILE_PATH_LUCENE);
args.sandbox = Paths.get(host.getStorageSandbox()).getParent(); args.port = 0; VerificationHost newHost = VerificationHost.create(args);
args.sandbox = Paths.get(host.getStorageSandbox()).getParent(); args.port = 0; VerificationHost newHost = VerificationHost.create(args);
this.host.logMemoryInfo(); File f = new File(this.host.getStorageSandbox()); this.host.log("Sandbox: %s, Disk: free %d, usable: %d, total: %d", f.toURI(), f.getFreeSpace(),
this.host.logMemoryInfo(); File f = new File(this.host.getStorageSandbox()); this.host.log("Sandbox: %s, Disk: free %d, usable: %d, total: %d", f.toURI(), f.getFreeSpace(),