org.apache.lucene.util.Constants Java Examples
The following examples show how to use
org.apache.lucene.util.Constants.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Node.java From crate with Apache License 2.0 | 6 votes |
private void logVersion(Logger logger, JvmInfo jvmInfo) { logger.info( "version[{}], pid[{}], build[{}/{}], OS[{}/{}/{}], JVM[{}/{}/{}/{}]", Version.displayVersion(Version.CURRENT, Version.CURRENT.isSnapshot()), jvmInfo.pid(), Build.CURRENT.hashShort(), Build.CURRENT.timestamp(), Constants.OS_NAME, Constants.OS_VERSION, Constants.OS_ARCH, Constants.JVM_VENDOR, Constants.JVM_NAME, Constants.JAVA_VERSION, Constants.JVM_VERSION); warnIfPreRelease(Version.CURRENT, Version.CURRENT.isSnapshot(), logger); }
Example #2
Source File: Seccomp.java From Elasticsearch with Apache License 2.0 | 6 votes |
static void solarisImpl() { // first be defensive: we can give nice errors this way, at the very least. boolean supported = Constants.SUN_OS; if (supported == false) { throw new IllegalStateException("bug: should not be trying to initialize priv_set for an unsupported OS"); } // we couldn't link methods, could be some really ancient Solaris or some bug if (libc_solaris == null) { throw new UnsupportedOperationException("priv_set unavailable: could not link methods. requires Solaris 10+"); } // drop a null-terminated list of privileges if (libc_solaris.priv_set(PRIV_OFF, PRIV_ALLSETS, PRIV_PROC_FORK, PRIV_PROC_EXEC, null) != 0) { throw new UnsupportedOperationException("priv_set unavailable: priv_set(): " + JNACLibrary.strerror(Native.getLastError())); } logger.debug("Solaris priv_set initialization successful"); }
Example #3
Source File: SoftAutoCommitTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@Before public void createMonitor() throws Exception { assumeFalse("This test is not working on Windows (or maybe machines with only 2 CPUs)", Constants.WINDOWS); SolrCore core = h.getCore(); updater = (DirectUpdateHandler2) core.getUpdateHandler(); updater.setCommitWithinSoftCommit(true); // foce to default, let tests change as needed monitor = new MockEventListener(); core.registerNewSearcherListener(monitor); updater.registerSoftCommitCallback(monitor); updater.registerCommitCallback(monitor); // isolate searcher getting ready from this test monitor.searcher.poll(5000, MILLISECONDS); }
Example #4
Source File: SolrTestCaseJ4.java From lucene-solr with Apache License 2.0 | 6 votes |
private static SSLTestConfig buildSSLConfig() { SSLRandomizer sslRandomizer = SSLRandomizer.getSSLRandomizerForClass(RandomizedContext.current().getTargetClass()); if (Constants.MAC_OS_X) { // see SOLR-9039 // If a solution is found to remove this, please make sure to also update // TestMiniSolrCloudClusterSSL.testSslAndClientAuth as well. sslRandomizer = new SSLRandomizer(sslRandomizer.ssl, 0.0D, (sslRandomizer.debug + " w/ MAC_OS_X supressed clientAuth")); } SSLTestConfig result = sslRandomizer.createSSLTestConfig(); if (log.isInfoEnabled()) { log.info("Randomized ssl ({}) and clientAuth ({}) via: {}", result.isSSLMode(), result.isClientAuthMode(), sslRandomizer.debug); } return result; }
Example #5
Source File: JNANatives.java From crate with Apache License 2.0 | 6 votes |
static void trySetMaxNumberOfThreads() { if (Constants.LINUX) { // this is only valid on Linux and the value *is* different on OS X // see /usr/include/sys/resource.h on OS X // on Linux the resource RLIMIT_NPROC means *the number of threads* // this is in opposition to BSD-derived OSes final int rlimit_nproc = 6; final JNACLibrary.Rlimit rlimit = new JNACLibrary.Rlimit(); if (JNACLibrary.getrlimit(rlimit_nproc, rlimit) == 0) { MAX_NUMBER_OF_THREADS = rlimit.rlim_cur.longValue(); } else { LOGGER.warn("unable to retrieve max number of threads [" + JNACLibrary.strerror(Native.getLastError()) + "]"); } } }
Example #6
Source File: Seccomp.java From Elasticsearch with Apache License 2.0 | 6 votes |
/** * Attempt to drop the capability to execute for the process. * <p> * This is best effort and OS and architecture dependent. It may throw any Throwable. * @return 0 if we can do this for application threads, 1 for the entire process */ static int init(Path tmpFile) throws Throwable { if (Constants.LINUX) { return linuxImpl(); } else if (Constants.MAC_OS_X) { // try to enable both mechanisms if possible bsdImpl(); macImpl(tmpFile); return 1; } else if (Constants.SUN_OS) { solarisImpl(); return 1; } else if (Constants.FREE_BSD || OPENBSD) { bsdImpl(); return 1; } else if (Constants.WINDOWS) { windowsImpl(); return 1; } else { throw new UnsupportedOperationException("syscall filtering not supported for OS: '" + Constants.OS_NAME + "'"); } }
Example #7
Source File: TestSolrDeletionPolicy1.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testCommitAge() throws InterruptedException { assumeFalse("This test is not working on Windows (or maybe machines with only 2 CPUs)", Constants.WINDOWS); IndexDeletionPolicyWrapper delPolicy = h.getCore().getDeletionPolicy(); addDocs(); Map<Long, IndexCommit> commits = delPolicy.getCommits(); IndexCommit ic = delPolicy.getLatestCommit(); String agestr = ((SolrDeletionPolicy) (delPolicy.getWrappedDeletionPolicy())).getMaxCommitAge().replaceAll("[a-zA-Z]", "").replaceAll("-", ""); long age = Long.parseLong(agestr); Thread.sleep(age); assertU(adoc("id", String.valueOf(6), "name", "name" + String.valueOf(6))); assertU(optimize()); assertQ("return all docs", req("id:[0 TO 6]"), "*[count(//doc)=6]" ); commits = delPolicy.getCommits(); assertTrue(!commits.containsKey(ic.getGeneration())); }
Example #8
Source File: ReproduceInfoPrinter.java From crate with Apache License 2.0 | 6 votes |
@Override public void testFailure(Failure failure) throws Exception { // Ignore assumptions. if (failure.getException() instanceof AssumptionViolatedException) { return; } final String gradlew = Constants.WINDOWS ? "gradlew" : "./gradlew"; final StringBuilder b = new StringBuilder("REPRODUCE WITH: " + gradlew + " "); String task = System.getProperty("tests.task"); // TODO: enforce (intellij still runs the runner?) or use default "test" but that won't work for integ b.append(task); GradleMessageBuilder gradleMessageBuilder = new GradleMessageBuilder(b); gradleMessageBuilder.appendAllOpts(failure.getDescription()); printToErr(b.toString()); }
Example #9
Source File: ImpersonationUtil.java From lucene-solr with Apache License 2.0 | 6 votes |
static String getUsersFirstGroup() throws Exception { String group = "*"; // accept any group if a group can't be found if (!Constants.WINDOWS) { // does not work on Windows! org.apache.hadoop.security.Groups hGroups = new org.apache.hadoop.security.Groups(new Configuration()); try { List<String> g = hGroups.getGroups(System.getProperty("user.name")); if (g != null && g.size() > 0) { group = g.get(0); } } catch (NullPointerException npe) { // if user/group doesn't exist on test box } } return group; }
Example #10
Source File: FsDirectoryService.java From Elasticsearch with Apache License 2.0 | 6 votes |
protected Directory newFSDirectory(Path location, LockFactory lockFactory) throws IOException { final String storeType = indexSettings.get(IndexStoreModule.STORE_TYPE, IndexStoreModule.Type.DEFAULT.getSettingsKey()); if (IndexStoreModule.Type.FS.match(storeType) || IndexStoreModule.Type.DEFAULT.match(storeType)) { final FSDirectory open = FSDirectory.open(location, lockFactory); // use lucene defaults if (open instanceof MMapDirectory && Constants.WINDOWS == false) { return newDefaultDir(location, (MMapDirectory) open, lockFactory); } return open; } else if (IndexStoreModule.Type.SIMPLEFS.match(storeType)) { return new SimpleFSDirectory(location, lockFactory); } else if (IndexStoreModule.Type.NIOFS.match(storeType)) { return new NIOFSDirectory(location, lockFactory); } else if (IndexStoreModule.Type.MMAPFS.match(storeType)) { return new MMapDirectory(location, lockFactory); } throw new IllegalArgumentException("No directory found for type [" + storeType + "]"); }
Example #11
Source File: NodeStatsTest.java From crate with Apache License 2.0 | 6 votes |
@Test public void testSysNodsOsInfo() throws Exception { SQLResponse response = execute("select os_info from sys.nodes limit 1"); Map results = (Map) response.rows()[0][0]; assertThat(response.rowCount(), is(1L)); assertThat((Integer) results.get("available_processors"), greaterThan(0)); assertEquals(Constants.OS_NAME, results.get("name")); assertEquals(Constants.OS_ARCH, results.get("arch")); assertEquals(Constants.OS_VERSION, results.get("version")); Map<String, Object> jvmObj = new HashMap<>(4); jvmObj.put("version", Constants.JAVA_VERSION); jvmObj.put("vm_name", Constants.JVM_NAME); jvmObj.put("vm_vendor", Constants.JVM_VENDOR); jvmObj.put("vm_version", Constants.JVM_VERSION); assertEquals(jvmObj, results.get("jvm")); }
Example #12
Source File: ESFileStore.java From Elasticsearch with Apache License 2.0 | 6 votes |
@SuppressForbidden(reason = "tries to determine if disk is spinning") // TODO: move PathUtils to be package-private here instead of // public+forbidden api! ESFileStore(FileStore in) { this.in = in; Boolean spins; // Lucene's IOUtils.spins only works on Linux today: if (Constants.LINUX) { try { spins = IOUtils.spins(PathUtils.get(getMountPointLinux(in))); } catch (Exception e) { spins = null; } } else { spins = null; } this.spins = spins; }
Example #13
Source File: Environment.java From Elasticsearch with Apache License 2.0 | 6 votes |
/** * Returns true if the path is writable. * Acts just like {@link Files#isWritable(Path)}, except won't * falsely return false for paths on SUBST'd drive letters * See https://bugs.openjdk.java.net/browse/JDK-8034057 * Note this will set the file modification time (to its already-set value) * to test access. */ @SuppressForbidden(reason = "works around https://bugs.openjdk.java.net/browse/JDK-8034057") public static boolean isWritable(Path path) throws IOException { boolean v = Files.isWritable(path); if (v || Constants.WINDOWS == false) { return v; } // isWritable returned false on windows, the hack begins!!!!!! // resetting the modification time is the least destructive/simplest // way to check for both files and directories, and fails early just // in getting the current value if file doesn't exist, etc try { Files.setLastModifiedTime(path, Files.getLastModifiedTime(path)); return true; } catch (Throwable e) { return false; } }
Example #14
Source File: TransportSQLActionClassLifecycleTest.java From crate with Apache License 2.0 | 6 votes |
@Test public void testArithmeticFunctions() throws Exception { execute("select ((2 * 4 - 2 + 1) / 2) % 3 from sys.cluster"); assertThat(response.cols()[0], is("0")); assertThat(response.rows()[0][0], is(0)); execute("select ((2 * 4.0 - 2 + 1) / 2) % 3 from sys.cluster"); assertThat(response.rows()[0][0], is(0.5)); execute("select ? + 2 from sys.cluster", $(1)); assertThat(response.rows()[0][0], is(3)); if (!Constants.WINDOWS) { response = execute("select load['1'] + load['5'], load['1'], load['5'] from sys.nodes limit 1"); assertEquals(response.rows()[0][0], (Double) response.rows()[0][1] + (Double) response.rows()[0][2]); } }
Example #15
Source File: MockFileSystemTestCase.java From lucene-solr with Apache License 2.0 | 6 votes |
private void implTestURI(String fileName) throws IOException { assumeFalse("broken on J9: see https://issues.apache.org/jira/browse/LUCENE-6517", Constants.JAVA_VENDOR.startsWith("IBM")); Path dir = wrap(createTempDir()); Path f1 = null; try { f1 = dir.resolve(fileName); } catch (InvalidPathException ipe) { assumeNoException("couldn't resolve '"+fileName+"'", ipe); } URI uri = f1.toUri(); Path f2 = dir.getFileSystem().provider().getPath(uri); assertEquals(f1, f2); dir.getFileSystem().close(); }
Example #16
Source File: TestIndexWriter.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testPendingDeletesAlreadyWrittenFiles() throws IOException { Path path = createTempDir(); // irony: currently we don't emulate windows well enough to work on windows! assumeFalse("windows is not supported", Constants.WINDOWS); // Use WindowsFS to prevent open files from being deleted: FileSystem fs = new WindowsFS(path.getFileSystem()).getFileSystem(URI.create("file:///")); Path root = new FilterPath(path, fs); DirectoryReader reader; // MMapDirectory doesn't work because it closes its file handles after mapping! try (FSDirectory dir = new NIOFSDirectory(root)) { IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random())); IndexWriter w = new IndexWriter(dir, iwc); w.commit(); IndexInput in = dir.openInput("segments_1", IOContext.DEFAULT); w.addDocument(new Document()); w.close(); assertTrue(dir.getPendingDeletions().size() > 0); // make sure we get NoSuchFileException if we try to delete and already-pending-delete file: expectThrows(NoSuchFileException.class, () -> { dir.deleteFile("segments_1"); }); new IndexWriter(dir, new IndexWriterConfig(new MockAnalyzer(random()))).close(); in.close(); } }
Example #17
Source File: TestSSLTestConfig.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testFailIfUserRunsTestsWithJVMThatHasKnownSSLBugs() { // NOTE: If there is some future JVM version, where all available "ea" builds are known to be buggy, // but we still want to be able to use for running tests (ie: via jenkins) to look for *other* bugs, // then those -ea versions can be "white listed" here... try { SSLTestConfig.assumeSslIsSafeToTest(); } catch (org.junit.AssumptionViolatedException ave) { fail("Current JVM (" + Constants.JVM_NAME + " / " + Constants.JVM_VERSION + ") is known to have SSL Bugs. Other tests that (explicitly or via randomization) " + " use SSL will be SKIPed"); } }
Example #18
Source File: SSLTestConfig.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * Helper method for sanity checking if it's safe to use SSL on this JVM * * @see <a href="https://issues.apache.org/jira/browse/SOLR-12988">SOLR-12988</a> * @throws org.junit.internal.AssumptionViolatedException if this JVM is known to have SSL problems */ public static void assumeSslIsSafeToTest() { if (Constants.JVM_NAME.startsWith("OpenJDK") || Constants.JVM_NAME.startsWith("Java HotSpot(TM)")) { RandomizedTest.assumeFalse("Test (or randomization for this seed) wants to use SSL, " + "but SSL is known to fail on your JVM: " + Constants.JVM_NAME + " / " + Constants.JVM_VERSION, isOpenJdkJvmVersionKnownToHaveProblems(Constants.JVM_VERSION)); } }
Example #19
Source File: JNANatives.java From crate with Apache License 2.0 | 5 votes |
static void addConsoleCtrlHandler(ConsoleCtrlHandler handler) { // The console Ctrl handler is necessary on Windows platforms only. if (Constants.WINDOWS) { try { boolean result = JNAKernel32Library.getInstance().addConsoleCtrlHandler(handler); if (result) { LOGGER.debug("console ctrl handler correctly set"); } else { LOGGER.warn("unknown error {} when adding console ctrl handler", Native.getLastError()); } } catch (UnsatisfiedLinkError e) { // this will have already been logged by Kernel32Library, no need to repeat it } } }
Example #20
Source File: ScriptEngineTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@BeforeClass public static void beforeClass() throws Exception { assumeFalse("https://twitter.com/UweSays/status/260487231880433664 / SOLR-4233: OS X bogusly starts AWT!", Constants.MAC_OS_X); Assume.assumeNotNull((new ScriptEngineManager()).getEngineByExtension("js")); Assume.assumeNotNull((new ScriptEngineManager()).getEngineByName("JavaScript")); }
Example #21
Source File: OsProbe.java From crate with Apache License 2.0 | 5 votes |
public OsStats osStats() { final OsStats.Cpu cpu = new OsStats.Cpu(getSystemCpuPercent(), getSystemLoadAverage()); final OsStats.Mem mem = new OsStats.Mem(getTotalPhysicalMemorySize(), getFreePhysicalMemorySize()); final OsStats.Swap swap = new OsStats.Swap(getTotalSwapSpaceSize(), getFreeSwapSpaceSize()); final OsStats.Cgroup cgroup = Constants.LINUX ? getCgroup() : null; return new OsStats(System.currentTimeMillis(), cpu, mem, swap, cgroup); }
Example #22
Source File: Seccomp.java From Elasticsearch with Apache License 2.0 | 5 votes |
/** try to install our custom rule profile into sandbox_init() to block execution */ private static void macImpl(Path tmpFile) throws IOException { // first be defensive: we can give nice errors this way, at the very least. boolean supported = Constants.MAC_OS_X; if (supported == false) { throw new IllegalStateException("bug: should not be trying to initialize seatbelt for an unsupported OS"); } // we couldn't link methods, could be some really ancient OS X (< Leopard) or some bug if (libc_mac == null) { throw new UnsupportedOperationException("seatbelt unavailable: could not link methods. requires Leopard or above."); } // write rules to a temporary file, which will be passed to sandbox_init() Path rules = Files.createTempFile(tmpFile, "es", "sb"); Files.write(rules, Collections.singleton(SANDBOX_RULES), StandardCharsets.UTF_8); boolean success = false; try { PointerByReference errorRef = new PointerByReference(); int ret = libc_mac.sandbox_init(rules.toAbsolutePath().toString(), SANDBOX_NAMED, errorRef); // if sandbox_init() fails, add the message from the OS (e.g. syntax error) and free the buffer if (ret != 0) { Pointer errorBuf = errorRef.getValue(); RuntimeException e = new UnsupportedOperationException("sandbox_init(): " + errorBuf.getString(0)); libc_mac.sandbox_free_error(errorBuf); throw e; } logger.debug("OS X seatbelt initialization successful"); success = true; } finally { if (success) { Files.delete(rules); } else { IOUtils.deleteFilesIgnoringExceptions(rules); } } }
Example #23
Source File: JNANatives.java From crate with Apache License 2.0 | 5 votes |
/** Returns true if user is root, false if not, or if we don't know */ static boolean definitelyRunningAsRoot() { if (Constants.WINDOWS) { return false; // don't know } try { return JNACLibrary.geteuid() == 0; } catch (UnsatisfiedLinkError e) { // this will have already been logged by Kernel32Library, no need to repeat it return false; } }
Example #24
Source File: JNANatives.java From crate with Apache License 2.0 | 5 votes |
static void trySetMaxFileSize() { if (Constants.LINUX || Constants.MAC_OS_X) { final JNACLibrary.Rlimit rlimit = new JNACLibrary.Rlimit(); if (JNACLibrary.getrlimit(JNACLibrary.RLIMIT_FSIZE, rlimit) == 0) { MAX_FILE_SIZE = rlimit.rlim_cur.longValue(); } else { LOGGER.warn("unable to retrieve max file size [" + JNACLibrary.strerror(Native.getLastError()) + "]"); } } }
Example #25
Source File: FSDirectory.java From lucene-solr with Apache License 2.0 | 5 votes |
/** Just like {@link #open(Path)}, but allows you to * also specify a custom {@link LockFactory}. */ public static FSDirectory open(Path path, LockFactory lockFactory) throws IOException { if (Constants.JRE_IS_64BIT && MMapDirectory.UNMAP_SUPPORTED) { return new MMapDirectory(path, lockFactory); } else { return new NIOFSDirectory(path, lockFactory); } }
Example #26
Source File: JNANatives.java From crate with Apache License 2.0 | 5 votes |
static void trySetMaxSizeVirtualMemory() { if (Constants.LINUX || Constants.MAC_OS_X) { final JNACLibrary.Rlimit rlimit = new JNACLibrary.Rlimit(); if (JNACLibrary.getrlimit(JNACLibrary.RLIMIT_AS, rlimit) == 0) { MAX_SIZE_VIRTUAL_MEMORY = rlimit.rlim_cur.longValue(); } else { LOGGER.warn("unable to retrieve max size virtual memory [" + JNACLibrary.strerror(Native.getLastError()) + "]"); } } }
Example #27
Source File: TermVectorComponentDistributedTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@BeforeClass public static void betterNotBeJ9() { assumeFalse("FIXME: SOLR-5792: This test fails under IBM J9", Constants.JAVA_VENDOR.startsWith("IBM")); int statsType = TestUtil.nextInt(random(), 1, 3); if (statsType == 1) { System.setProperty("solr.statsCache", ExactStatsCache.class.getName()); } else if (statsType == 2) { System.setProperty("solr.statsCache", LRUStatsCache.class.getName()); } else { System.setProperty("solr.statsCache", LocalStatsCache.class.getName()); } }
Example #28
Source File: TestMiniSolrCloudClusterSSL.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testSslAndClientAuth() throws Exception { assumeFalse("SOLR-9039: SSL w/clientAuth does not work on MAC_OS_X", Constants.MAC_OS_X); final SSLTestConfig sslConfig = new SSLTestConfig(true, true); HttpClientUtil.setSocketFactoryRegistryProvider(sslConfig.buildClientSocketFactoryRegistryProvider()); Http2SolrClient.setDefaultSSLConfig(sslConfig.buildClientSSLConfig()); System.setProperty(ZkStateReader.URL_SCHEME, "https"); checkClusterWithNodeReplacement(sslConfig); }
Example #29
Source File: SaslZkACLProviderTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@BeforeClass public static void beforeClass() { assumeFalse("FIXME: This test fails on Java 9 (https://issues.apache.org/jira/browse/SOLR-8052)", Constants.JRE_IS_MINIMUM_JAVA9); assumeFalse("FIXME: SOLR-7040: This test fails under IBM J9", Constants.JAVA_VENDOR.startsWith("IBM")); System.setProperty("solrcloud.skip.autorecovery", "true"); System.setProperty("hostName", "localhost"); }
Example #30
Source File: FsProbe.java From crate with Apache License 2.0 | 5 votes |
public FsInfo stats(FsInfo previous, @Nullable ClusterInfo clusterInfo) throws IOException { if (!nodeEnv.hasNodeFile()) { return new FsInfo(System.currentTimeMillis(), null, new FsInfo.Path[0]); } NodePath[] dataLocations = nodeEnv.nodePaths(); FsInfo.Path[] paths = new FsInfo.Path[dataLocations.length]; for (int i = 0; i < dataLocations.length; i++) { paths[i] = getFSInfo(dataLocations[i]); } FsInfo.IoStats ioStats = null; if (Constants.LINUX) { Set<Tuple<Integer, Integer>> devicesNumbers = new HashSet<>(); for (int i = 0; i < dataLocations.length; i++) { if (dataLocations[i].majorDeviceNumber != -1 && dataLocations[i].minorDeviceNumber != -1) { devicesNumbers.add(Tuple.tuple(dataLocations[i].majorDeviceNumber, dataLocations[i].minorDeviceNumber)); } } ioStats = ioStats(devicesNumbers, previous); } DiskUsage leastDiskEstimate = null; DiskUsage mostDiskEstimate = null; if (clusterInfo != null) { leastDiskEstimate = clusterInfo.getNodeLeastAvailableDiskUsages().get(nodeEnv.nodeId()); mostDiskEstimate = clusterInfo.getNodeMostAvailableDiskUsages().get(nodeEnv.nodeId()); } return new FsInfo(System.currentTimeMillis(), ioStats, paths, leastDiskEstimate, mostDiskEstimate); }