Return-Path: X-Original-To: apmail-lucene-commits-archive@www.apache.org Delivered-To: apmail-lucene-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2260E10CE1 for ; Fri, 17 Apr 2015 11:07:46 +0000 (UTC) Received: (qmail 75300 invoked by uid 500); 17 Apr 2015 11:07:46 -0000 Mailing-List: contact commits-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@lucene.apache.org Delivered-To: mailing list commits@lucene.apache.org Received: (qmail 75287 invoked by uid 99); 17 Apr 2015 11:07:45 -0000 Received: from eris.apache.org (HELO hades.apache.org) (140.211.11.105) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 17 Apr 2015 11:07:45 +0000 Received: from hades.apache.org (localhost [127.0.0.1]) by hades.apache.org (ASF Mail Server at hades.apache.org) with ESMTP id CF2E8AC00B5 for ; Fri, 17 Apr 2015 11:07:45 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1674274 - /lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/mockfile/ExtrasFS.java Date: Fri, 17 Apr 2015 11:07:45 -0000 To: commits@lucene.apache.org From: rmuir@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20150417110745.CF2E8AC00B5@hades.apache.org> Author: rmuir Date: Fri Apr 17 11:07:45 2015 New Revision: 1674274 URL: http://svn.apache.org/r1674274 Log: LUCENE-6431: make ExtrasFS reproducible Modified: lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/mockfile/ExtrasFS.java Modified: lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/mockfile/ExtrasFS.java URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/mockfile/ExtrasFS.java?rev=1674274&r1=1674273&r2=1674274&view=diff ============================================================================== --- lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/mockfile/ExtrasFS.java (original) +++ lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/mockfile/ExtrasFS.java Fri Apr 17 11:07:45 2015 @@ -25,6 +25,8 @@ import java.nio.file.attribute.FileAttri import java.util.Random; import java.util.concurrent.atomic.AtomicLong; +import com.carrotsearch.randomizedtesting.RandomizedContext; + /** * Adds extra files/subdirectories when directories are created. *

@@ -33,30 +35,36 @@ import java.util.concurrent.atomic.Atomi * so we add them and see what breaks. *

* When a directory is created, sometimes a file or directory named - * "extraNNNN" will be included with it. + * "extra0" will be included with it. * All other filesystem operations are passed thru as normal. */ public class ExtrasFS extends FilterFileSystemProvider { - final AtomicLong counter = new AtomicLong(); - final Random random; + final int seed; /** * Create a new instance, wrapping {@code delegate}. */ public ExtrasFS(FileSystem delegate, Random random) { super("extras://", delegate); - this.random = random; + this.seed = random.nextInt(); } @Override public void createDirectory(Path dir, FileAttribute... attrs) throws IOException { - super.createDirectory(dir, attrs); + super.createDirectory(dir, attrs); // ok, we created the directory successfully. - if (random.nextInt(4) == 0) { + + // a little funky: we only look at hashcode (well-defined) of the target class name. + // using a generator won't reproduce, because we are a per-class resource. + // using hashing on filenames won't reproduce, because many of the names rely on other things + // the test class did. + // so a test gets terrorized with extras or gets none at all depending on the initial seed. + int hash = RandomizedContext.current().getTargetClass().toString().hashCode() ^ seed; + if ((hash & 3) == 0) { // lets add a bogus file... if this fails, we don't care, its best effort. try { - Path target = dir.resolve("extra" + counter.incrementAndGet()); - if (random.nextBoolean()) { + Path target = dir.resolve("extra0"); + if (hash < 0) { super.createDirectory(target); } else { Files.createFile(target);