Search in sources :

Example 16 with SuppressForbidden

use of org.apache.lucene.util.SuppressForbidden in project lucene-solr by apache.

the class IndexSplitter method main.

@SuppressForbidden(reason = "System.out required: command line tool")
public static void main(String[] args) throws Exception {
    if (args.length < 2) {
        System.err.println("Usage: IndexSplitter <srcDir> -l (list the segments and their sizes)");
        System.err.println("IndexSplitter <srcDir> <destDir> <segments>+");
        System.err.println("IndexSplitter <srcDir> -d (delete the following segments)");
        return;
    }
    Path srcDir = Paths.get(args[0]);
    IndexSplitter is = new IndexSplitter(srcDir);
    if (!Files.exists(srcDir)) {
        throw new Exception("srcdir:" + srcDir.toAbsolutePath() + " doesn't exist");
    }
    if (args[1].equals("-l")) {
        is.listSegments();
    } else if (args[1].equals("-d")) {
        List<String> segs = new ArrayList<>();
        for (int x = 2; x < args.length; x++) {
            segs.add(args[x]);
        }
        is.remove(segs.toArray(new String[0]));
    } else {
        Path targetDir = Paths.get(args[1]);
        List<String> segs = new ArrayList<>();
        for (int x = 2; x < args.length; x++) {
            segs.add(args[x]);
        }
        is.split(targetDir, segs.toArray(new String[0]));
    }
}
Also used : Path(java.nio.file.Path) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException) SuppressForbidden(org.apache.lucene.util.SuppressForbidden)

Example 17 with SuppressForbidden

use of org.apache.lucene.util.SuppressForbidden in project lucene-solr by apache.

the class TestIndexWriterOnJRECrash method forkTest.

/** fork ourselves in a new jvm. sets -Dtests.crashmode=true */
@SuppressForbidden(reason = "ProcessBuilder requires java.io.File for CWD")
public void forkTest() throws Exception {
    List<String> cmd = new ArrayList<>();
    cmd.add(Paths.get(System.getProperty("java.home"), "bin", "java").toString());
    cmd.add("-Xmx512m");
    cmd.add("-Dtests.crashmode=true");
    // passing NIGHTLY to this test makes it run for much longer, easier to catch it in the act...
    cmd.add("-Dtests.nightly=true");
    cmd.add("-DtempDir=" + tempDir);
    cmd.add("-Dtests.seed=" + SeedUtils.formatSeed(random().nextLong()));
    cmd.add("-ea");
    cmd.add("-cp");
    cmd.add(System.getProperty("java.class.path"));
    cmd.add("org.junit.runner.JUnitCore");
    cmd.add(getClass().getName());
    ProcessBuilder pb = new ProcessBuilder(cmd).directory(tempDir.toFile()).redirectInput(Redirect.INHERIT).redirectErrorStream(true);
    Process p = pb.start();
    // We pump everything to stderr.
    PrintStream childOut = System.err;
    Thread stdoutPumper = ThreadPumper.start(p.getInputStream(), childOut);
    if (VERBOSE)
        childOut.println(">>> Begin subprocess output");
    p.waitFor();
    stdoutPumper.join();
    if (VERBOSE)
        childOut.println("<<< End subprocess output");
}
Also used : PrintStream(java.io.PrintStream) ArrayList(java.util.ArrayList) SuppressForbidden(org.apache.lucene.util.SuppressForbidden)

Aggregations

SuppressForbidden (org.apache.lucene.util.SuppressForbidden)17 IOException (java.io.IOException)6 Path (java.nio.file.Path)6 Directory (org.apache.lucene.store.Directory)6 FSDirectory (org.apache.lucene.store.FSDirectory)5 ArrayList (java.util.ArrayList)4 BufferedReader (java.io.BufferedReader)2 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 LineNumberReader (java.io.LineNumberReader)2 OutputStream (java.io.OutputStream)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Field (java.lang.reflect.Field)2 Method (java.lang.reflect.Method)2 InetSocketAddress (java.net.InetSocketAddress)2 Socket (java.net.Socket)2 StringTokenizer (java.util.StringTokenizer)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Pattern (java.util.regex.Pattern)2 BufferedOutputStream (java.io.BufferedOutputStream)1