项目:Elasticsearch
文件:ESFileStore.java
@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;
}
项目:Elasticsearch
文件:Seccomp.java
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");
}
/**
* 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 Exception {
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 + "'");
}
}
项目:Elasticsearch
文件:Environment.java
/**
* 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;
}
}
项目:elasticsearch_my
文件:BaseXContentTestCase.java
public void testIterable() throws Exception {
Map<String,Iterable<?>> iterables = new HashMap<>();
iterables.put("{'iter':null}",(Iterable) null);
iterables.put("{'iter':[]}",Collections.emptyList());
iterables.put("{'iter':['a','b']}",Arrays.asList("a","b"));
final String path = Constants.WINDOWS ? "{'iter':'path\\\\to\\\\file'}" : "{'iter':'path/to/file'}";
iterables.put(path,PathUtils.get("path","to","file"));
final String paths = Constants.WINDOWS ? "{'iter':['a\\\\b\\\\c','c\\\\d']}" : "{'iter':['a/b/c','c/d']}";
iterables.put(paths,Arrays.asList(PathUtils.get("a","b","c"),PathUtils.get("c","d")));
for (Map.Entry<String,Iterable<?>> i : iterables.entrySet()) {
final String expected = i.getKey();
assertResult(expected,() -> builder().startObject().field("iter",i.getValue()).endobject());
assertResult(expected,() -> builder().startObject().field("iter").value(i.getValue()).endobject());
}
}
项目:elasticsearch_my
文件:JNANatives.java
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()) + "]");
}
}
}
项目:Elasticsearch
文件:FsDirectoryService.java
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 + "]");
}
项目:elasticsearch_my
文件:EvilJNANativesTests.java
public void testSetMaxSizeVirtualMemory() throws IOException {
if (Constants.LINUX) {
final List<String> lines = Files.readAllLines(PathUtils.get("/proc/self/limits"));
if (!lines.isEmpty()) {
for (String line : lines) {
if (line != null && line.startsWith("Max address space")) {
final String[] fields = line.split("\\s+");
final String limit = fields[3];
assertEquals(JNANatives.rlimitToString(JNANatives.MAX_SIZE_VIRTUAL_MEMORY),limit);
return;
}
}
}
fail("should have read max size virtual memory from /proc/self/limits");
} else if (Constants.MAC_OS_X) {
assertthat(JNANatives.MAX_SIZE_VIRTUAL_MEMORY,anyOf(equalTo(Long.MIN_VALUE),greaterThanorEqualTo(0L)));
} else {
assertthat(JNANatives.MAX_SIZE_VIRTUAL_MEMORY,equalTo(Long.MIN_VALUE));
}
}
项目:elasticsearch_my
文件:EvilJNANativesTests.java
public void testSetMaximumNumberOfThreads() throws IOException {
if (Constants.LINUX) {
final List<String> lines = Files.readAllLines(PathUtils.get("/proc/self/limits"));
if (!lines.isEmpty()) {
for (String line : lines) {
if (line != null && line.startsWith("Max processes")) {
final String[] fields = line.split("\\s+");
final long limit = "unlimited".equals(fields[2]) ? JNACLibrary.RLIM_INFINITY : Long.parseLong(fields[2]);
assertthat(JNANatives.MAX_NUMBER_OF_THREADS,equalTo(limit));
return;
}
}
}
fail("should have read max processes from /proc/self/limits");
} else {
assertthat(JNANatives.MAX_NUMBER_OF_THREADS,equalTo(-1L));
}
}
项目:elasticsearch_my
文件:SmokeTestClientIT.java
/**
* Create an index and index some docs
*/
public void testPutDocument() {
// Todo: remove when Netty 4.1.5 is upgraded to Netty 4.1.6 including https://github.com/netty/netty/pull/5778
assumeFalse("JDK is JDK 9",Constants.JRE_IS_MINIMUM_JAVA9);
Client client = getClient();
// START SNIPPET: java-doc-index-doc-simple
client.prepareIndex(index,"doc","1") // Index,Type,Id
.setSource("foo","bar") // Simple document: { "foo" : "bar" }
.get(); // Execute and wait for the result
// END SNIPPET: java-doc-index-doc-simple
// START SNIPPET: java-doc-admin-indices-refresh
// Prepare a refresh action on a given index,execute and wait for the result
client.admin().indices().prepareRefresh(index).get();
// END SNIPPET: java-doc-admin-indices-refresh
// START SNIPPET: java-doc-search-simple
SearchResponse searchResponse = client.prepareSearch(index).get();
assertthat(searchResponse.getHits().getTotalHits(),is(1L));
// END SNIPPET: java-doc-search-simple
}
项目:elasticsearch_my
文件:LambdaTests.java
public void testReservedCapture() {
assumeFalse("JDK is JDK 9",Constants.JRE_IS_MINIMUM_JAVA9);
String compare = "boolean compare(supplier s,def v) {s.get() == v}";
assertEquals(true,exec(compare + "compare(() -> new ArrayList(),new ArrayList())"));
assertEquals(true,exec(compare + "compare(() -> { new ArrayList() },new ArrayList())"));
Map<String,Object> params = new HashMap<>();
params.put("key","value");
params.put("number",2);
assertEquals(true,exec(compare + "compare(() -> { return params['key'] },'value')",params,true));
assertEquals(false,exec(compare + "compare(() -> { return params['nokey'] },true));
assertEquals(true,null)",exec(compare + "compare(() -> { return params['number'] },2)",exec(compare + "compare(() -> { if (params['number'] == 2) { return params['number'] }" +
"else { return params['key'] } },exec(compare + "compare(() -> { if (params['number'] == 1) { return params['number'] }" +
"else { return params['key'] } },true));
}
项目:Elasticsearch
文件:JVMCheck.java
/**
* Checks that the current JVM is "ok". This means it doesn't have severe bugs that cause data corruption.
*/
static void check() {
if (Boolean.parseBoolean(System.getProperty(JVM_BYPASS))) {
Loggers.getLogger(JVMCheck.class).warn("bypassing jvm version check for version [{}],this can result in data corruption!",fullVersion());
} else if ("Oracle Corporation".equals(Constants.JVM_vendOR)) {
HotspotBug bug = JVM_broKEN_HOTSPOT_VERSIONS.get(Constants.JVM_VERSION);
if (bug != null) {
if (bug.workAround != null && ManagementFactory.getRuntimeMXBean().getInputArguments().contains(bug.workAround)) {
Loggers.getLogger(JVMCheck.class).warn(bug.getWarningMessage());
} else {
throw new RuntimeException(bug.getErrorMessage());
}
}
} else if ("IBM Corporation".equals(Constants.JVM_vendOR)) {
// currently some old JVM versions from IBM will easily result in index corruption.
// 2.8+ seems ok for ES from testing.
float version = Float.POSITIVE_INFINITY;
try {
version = Float.parseFloat(Constants.JVM_VERSION);
} catch (NumberFormatException ignored) {
// this is just a simple best-effort to detect old runtimes,// if we cannot parse it,we don't fail.
}
if (version < 2.8f) {
StringBuilder sb = new StringBuilder();
sb.append("IBM J9 runtimes < 2.8 suffer from several bugs which can cause data corruption.");
sb.append(System.lineseparator());
sb.append("Your version: " + fullVersion());
sb.append(System.lineseparator());
sb.append("Please upgrade the JVM to a recent IBM JDK");
throw new RuntimeException(sb.toString());
}
}
}
项目:elasticsearch_my
文件:AugmentationTests.java
public void testIterable_AsList() {
assumeFalse("JDK is JDK 9",Constants.JRE_IS_MINIMUM_JAVA9);
assertEquals(true,exec("List l = new ArrayList(); return l.asList() === l"));
assertEquals(5,exec("Set l = new HashSet(); l.add(5); return l.asList()[0]"));
}
项目:elasticsearch_my
文件:AugmentationTests.java
public void testCollection_Collect() {
assumeFalse("JDK is JDK 9",Constants.JRE_IS_MINIMUM_JAVA9);
assertEquals(Arrays.asList(2,3),exec("List l = new ArrayList(); l.add(1); l.add(2); l.collect(x -> x + 1)"));
assertEquals(asSet(2,exec("List l = new ArrayList(); l.add(1); l.add(2); l.collect(new HashSet(),x -> x + 1)"));
}
项目:elasticsearch_my
文件:JNANatives.java
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()) + "]");
}
}
}
/** 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));
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);
}
}
}
项目:elasticsearch_my
文件:AugmentationTests.java
public void testCollection_FindResult() {
assumeFalse("JDK is JDK 9",Constants.JRE_IS_MINIMUM_JAVA9);
assertEquals("found",exec("List l = new ArrayList(); l.add(1); l.add(2); return l.findResult(x -> x > 1 ? 'found' : null)"));
assertEquals("notfound",exec("List l = new ArrayList(); l.add(1); l.add(2); return l.findResult('notfound',x -> x > 10 ? 'found' : null)"));
}
项目:elasticsearch_my
文件:JNANatives.java
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
}
}
}
项目:elasticsearch_my
文件:AugmentationTests.java
public void testMap_Collect() {
assumeFalse("JDK is JDK 9",Constants.JRE_IS_MINIMUM_JAVA9);
assertEquals(Arrays.asList("one1","two2"),exec("Map m = new TreeMap(); m.one = 1; m.two = 2; m.collect((key,value) -> key + value)"));
assertEquals(asSet("one1",exec("Map m = new TreeMap(); m.one = 1; m.two = 2; m.collect(new HashSet(),(key,value) -> key + value)"));
}
项目:lams
文件:MMapDirectory.java
private IOException convertMapFailedIOException(IOException ioe,String resourceDescription,int bufSize) {
final String originalMessage;
final Throwable originalCause;
if (ioe.getCause() instanceof OutOfMemoryError) {
// nested OOM confuses users,because its "incorrect",just print a plain message:
originalMessage = "Map Failed";
originalCause = null;
} else {
originalMessage = ioe.getMessage();
originalCause = ioe.getCause();
}
final String moreInfo;
if (!Constants.JRE_IS_64BIT) {
moreInfo = "MMapDirectory should only be used on 64bit platforms,because the address space on 32bit operating systems is too small. ";
} else if (Constants.WINDOWS) {
moreInfo = "Windows is unfortunately very limited on virtual address space. If your index size is several hundred Gigabytes,consider changing to Linux. ";
} else if (Constants.LINUX) {
moreInfo = "Please review 'ulimit -v','ulimit -m' (both should return 'unlimited'),and 'sysctl vm.max_map_count'. ";
} else {
moreInfo = "Please review 'ulimit -v','ulimit -m' (both should return 'unlimited'). ";
}
final IOException newIoe = new IOException(String.format(Locale.ENGLISH,"%s: %s [this may be caused by lack of enough unfragmented virtual address space "+
"or too restrictive virtual memory limits enforced by the operating system,"+
"preventing us to map a chunk of %d bytes. %sMore information: "+
"http://blog.thetaphi.de/2012/07/use-lucenes-mmapdirectory-on-64bit.html]",originalMessage,resourceDescription,bufSize,moreInfo),originalCause);
newIoe.setStackTrace(ioe.getStackTrace());
return newIoe;
}
项目:elasticsearch_my
文件:AugmentationTests.java
public void testMap_FindResult() {
assumeFalse("JDK is JDK 9",exec("Map m = new TreeMap(); m.one = 1; m.two = 2; return m.findResult((key,value) -> value == 2 ? 'found' : null)"));
assertEquals("notfound",exec("Map m = new TreeMap(); m.one = 1; m.two = 2; " +
"return m.findResult('notfound',value) -> value == 10 ? 'found' : null)"));
}
项目:elasticsearch_my
文件:BootstrapCheckTests.java
public void testMaxSizeVirtualMemory() throws NodeValidationException {
final long rlimInfinity = Constants.MAC_OS_X ? 9223372036854775807L : -1L;
final AtomicLong maxSizeVirtualMemory = new AtomicLong(randomIntBetween(0,Integer.MAX_VALUE));
final BootstrapChecks.MaxSizeVirtualMemoryCheck check = new BootstrapChecks.MaxSizeVirtualMemoryCheck() {
@Override
long getMaxSizeVirtualMemory() {
return maxSizeVirtualMemory.get();
}
@Override
long getRlimInfinity() {
return rlimInfinity;
}
};
final NodeValidationException e = expectThrows(
NodeValidationException.class,() -> BootstrapChecks.check(true,Collections.singletonList(check),"testMaxSizeVirtualMemory"));
assertthat(e.getMessage(),containsstring("max size virtual memory"));
maxSizeVirtualMemory.set(rlimInfinity);
BootstrapChecks.check(true,"testMaxSizeVirtualMemory");
// nothing should happen if max size virtual memory is not
// available
maxSizeVirtualMemory.set(Long.MIN_VALUE);
BootstrapChecks.check(true,"testMaxSizeVirtualMemory");
}
项目:elasticsearch_my
文件:IndexShardTests.java
public void testShardStats() throws IOException {
IndexShard shard = newStartedShard();
ShardStats stats = new ShardStats(shard.routingEntry(),shard.shardpath(),new CommonStats(new IndicesQueryCache(Settings.EMPTY),shard,new CommonStatsFlags()),shard.commitStats(),shard.seqNoStats());
assertEquals(shard.shardpath().getRootDataPath().toString(),stats.getDataPath());
assertEquals(shard.shardpath().getRootStatePath().toString(),stats.getStatePath());
assertEquals(shard.shardpath().isCustomDataPath(),stats.isCustomDataPath());
if (randomBoolean() || true) { // try to serialize it to ensure values survive the serialization
BytesstreamOutput out = new BytesstreamOutput();
stats.writeto(out);
StreamInput in = out.bytes().streaminput();
stats = ShardStats.readShardStats(in);
}
XContentBuilder builder = jsonBuilder();
builder.startObject();
stats.toXContent(builder,EMPTY_ParaMS);
builder.endobject();
String xContent = builder.string();
StringBuilder expectedSubSequence = new StringBuilder("\"shard_path\":{\"state_path\":\"");
expectedSubSequence.append(shard.shardpath().getRootStatePath().toString());
expectedSubSequence.append("\",\"data_path\":\"");
expectedSubSequence.append(shard.shardpath().getRootDataPath().toString());
expectedSubSequence.append("\",\"is_custom_data_path\":").append(shard.shardpath().isCustomDataPath()).append("}");
if (Constants.WINDOWS) {
// Some path weirdness on windows
} else {
assertTrue(xContent.contains(expectedSubSequence));
}
closeShards(shard);
}
项目:elasticsearch_my
文件:SpawnerNoBootstrapTests.java
/**
* Two plugins - one with a controller daemon and one without.
*/
public void testControllerSpawn() throws IOException,InterruptedException {
// On Windows you cannot directly run a batch file - you have to run cmd.exe with the batch file
// as an argument and that's out of the remit of the controller daemon process spawner. If
// you need to build on Windows,just don't run this test. The process spawner itself will work
// with native processes.
assumeFalse("This test does not work on Windows",Constants.WINDOWS);
Path esHome = createTempDir().resolve("esHome");
Settings.Builder settingsBuilder = Settings.builder();
settingsBuilder.put(Environment.PATH_HOME_SETTING.getKey(),esHome.toString());
Settings settings = settingsBuilder.build();
Environment environment = new Environment(settings);
// This plugin WILL have a controller daemon
Path plugin = environment.pluginsFile().resolve("test_plugin");
Files.createDirectories(plugin);
Path controllerProgram = Spawner.makeSpawnPath(plugin);
createControllerProgram(controllerProgram);
// This plugin will NOT have a controller daemon
Path otherPlugin = environment.pluginsFile().resolve("other_plugin");
Files.createDirectories(otherPlugin);
Spawner spawner = new Spawner();
spawner.spawnNativePluginControllers(environment);
List<Process> processes = spawner.getProcesses();
// 1 because there should only be a reference in the list for the plugin that had the controller daemon,not the other plugin
assertEquals(1,processes.size());
Process process = processes.get(0);
try (BufferedReader stdoutReader = new BufferedReader(new InputStreamReader(process.getInputStream(),StandardCharsets.UTF_8))) {
String line = stdoutReader.readLine();
assertEquals("I am alive",line);
spawner.close();
// Fail if the process doesn't die within 1 second - usually it will be even quicker but it depends on OS scheduling
assertTrue(process.waitFor(1,TimeUnit.SECONDS));
}
}
项目:elasticsearch_my
文件:FunctionRefTests.java
public void testCtorMethodReference() {
assumeFalse("JDK is JDK 9",Constants.JRE_IS_MINIMUM_JAVA9);
assertEquals(3.0D,exec("List l = new ArrayList(); l.add(1.0); l.add(2.0); " +
"DoubleStream doubleStream = l.stream().mapTodouble(Double::doubleValue);" +
"DoubleSummaryStatistics stats = doubleStream.collect(DoubleSummaryStatistics::new," +
"DoubleSummaryStatistics::accept," +
"DoubleSummaryStatistics::combine); " +
"return stats.getSum()"));
}
static void windowsImpl() {
if (!Constants.WINDOWS) {
throw new IllegalStateException("bug: should not be trying to initialize ActiveProcessLimit for an unsupported OS");
}
JNAKernel32Library lib = JNAKernel32Library.getInstance();
// create a new Job
Pointer job = lib.CreateJobObjectW(null,null);
if (job == null) {
throw new UnsupportedOperationException("CreateJobObject: " + Native.getLastError());
}
try {
// retrieve the current basic limits of the job
int clazz = JNAKernel32Library.JOBOBJECT_BASIC_LIMIT_informatION_CLASS;
JNAKernel32Library.JOBOBJECT_BASIC_LIMIT_informatION limits = new JNAKernel32Library.JOBOBJECT_BASIC_LIMIT_informatION();
limits.write();
if (!lib.QueryinformationJobObject(job,clazz,limits.getPointer(),limits.size(),null)) {
throw new UnsupportedOperationException("QueryinformationJobObject: " + Native.getLastError());
}
limits.read();
// modify the number of active processes to be 1 (exactly the one process we will add to the job).
limits.ActiveProcessLimit = 1;
limits.LimitFlags = JNAKernel32Library.JOB_OBJECT_LIMIT_ACTIVE_PROCESS;
limits.write();
if (!lib.SetinformationJobObject(job,limits.size())) {
throw new UnsupportedOperationException("SetinformationJobObject: " + Native.getLastError());
}
// assign ourselves to the job
if (!lib.AssignProcesstoJobObject(job,lib.GetCurrentProcess())) {
throw new UnsupportedOperationException("AssignProcesstoJobObject: " + Native.getLastError());
}
} finally {
lib.CloseHandle(job);
}
logger.debug("Windows ActiveProcessLimit initialization successful");
}
项目:elasticsearch_my
文件:FunctionRefTests.java
public void testArrayCtorMethodRef() {
assumeFalse("JDK is JDK 9",Constants.JRE_IS_MINIMUM_JAVA9);
assertEquals(1.0D,exec("List l = new ArrayList(); l.add(1.0); l.add(2.0); " +
"def[] array = l.stream().toArray(Double[]::new);" +
"return array[0];"));
}
项目:elasticsearch_my
文件:FunctionRefTests.java
public void testArrayCtorMethodRefDef() {
assumeFalse("JDK is JDK 9",exec("def l = new ArrayList(); l.add(1.0); l.add(2.0); " +
"def[] array = l.stream().toArray(Double[]::new);" +
"return array[0];"));
}
项目:elasticsearch_my
文件:FsProbe.java
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);
}
项目:elasticsearch_my
文件:IndexStoreTests.java
private void doTestStoreDirectory(Index index,Path tempDir,String typesettingValue,IndexModule.Type type) throws IOException {
Settings.Builder settingsBuilder = Settings.builder()
.put(IndexMetaData.SETTING_VERSION_CREATED,Version.CURRENT);
if (typesettingValue != null) {
settingsBuilder.put(IndexModule.INDEX_STORE_TYPE_SETTING.getKey(),typesettingValue);
}
Settings settings = settingsBuilder.build();
IndexSettings indexSettings = IndexSettingsModule.newIndexSettings("foo",settings);
FsDirectoryService service = new FsDirectoryService(indexSettings,new Shardpath(false,tempDir,new ShardId(index,0)));
try (Directory directory = service.newFSDirectory(tempDir,NoLockFactory.INSTANCE)) {
switch (type) {
case NIOFS:
assertTrue(type + " " + directory.toString(),directory instanceof NIOFSDirectory);
break;
case MMapfs:
assertTrue(type + " " + directory.toString(),directory instanceof MMapDirectory);
break;
case SIMPLEFS:
assertTrue(type + " " + directory.toString(),directory instanceof SimpleFSDirectory);
break;
case FS:
if (Constants.JRE_IS_64BIT && MMapDirectory.UNMAP_SUPPORTED) {
assertTrue(directory.toString(),directory instanceof MMapDirectory);
} else if (Constants.WINDOWS) {
assertTrue(directory.toString(),directory instanceof SimpleFSDirectory);
} else {
assertTrue(directory.toString(),directory instanceof NIOFSDirectory);
}
break;
default:
fail();
}
}
}
项目:elasticsearch_my
文件:FunctionRefTests.java
public void testCapturingMethodReferenceMultipleLambdas() {
assumeFalse("JDK is JDK 9",Constants.JRE_IS_MINIMUM_JAVA9);
assertEquals("testingcdefg",exec(
"String x = 'testing';" +
"String y = 'abcdefg';" +
"org.elasticsearch.painless.FeatureTest test = new org.elasticsearch.painless.FeatureTest(2,3);" +
"return test.twoFunctionsOfX(x::concat,y::substring);"));
}
项目:elasticsearch_my
文件:FunctionRefTests.java
public void testCapturingMethodReferenceMultipleLambdasDefImpls() {
assumeFalse("JDK is JDK 9",exec(
"def x = 'testing';" +
"def y = 'abcdefg';" +
"org.elasticsearch.painless.FeatureTest test = new org.elasticsearch.painless.FeatureTest(2,y::substring);"));
}
项目:elasticsearch_my
文件:FunctionRefTests.java
public void testCapturingMethodReferenceMultipleLambdasDefInterface() {
assumeFalse("JDK is JDK 9",exec(
"String x = 'testing';" +
"String y = 'abcdefg';" +
"def test = new org.elasticsearch.painless.FeatureTest(2,y::substring);"));
}
项目:elasticsearch_my
文件:FunctionRefTests.java
public void testCapturingMethodReferenceMultipleLambdasDefEverywhere() {
assumeFalse("JDK is JDK 9",exec(
"def x = 'testing';" +
"def y = 'abcdefg';" +
"def test = new org.elasticsearch.painless.FeatureTest(2,y::substring);"));
}
项目:elasticsearch_my
文件:SimpleSearchIT.java
public void testLocaleDependentDate() throws Exception {
assumeFalse("Locals are buggy on JDK9EA",Constants.JRE_IS_MINIMUM_JAVA9 && systemPropertyAsBoolean("tests.security.manager",false));
assertAcked(prepareCreate("test")
.addMapping("type1",jsonBuilder().startObject()
.startObject("type1")
.startObject("properties")
.startObject("date_field")
.field("type","date")
.field("format","E,d MMM yyyy HH:mm:ss Z")
.field("locale","de")
.endobject()
.endobject()
.endobject()
.endobject()));
ensureGreen();
for (int i = 0; i < 10; i++) {
client().prepareIndex("test","type1","" + i).setSource("date_field","Mi,06 Dez 2000 02:55:00 -0800").execute().actionGet();
client().prepareIndex("test","" + (10 + i)).setSource("date_field","Do,07 Dez 2000 02:55:00 -0800").execute().actionGet();
}
refresh();
for (int i = 0; i < 10; i++) {
SearchResponse searchResponse = client().prepareSearch("test")
.setQuery(QueryBuilders.rangeQuery("date_field").gte("Di,05 Dez 2000 02:55:00 -0800").lte("Do,07 Dez 2000 00:00:00 -0800"))
.execute().actionGet();
assertHitCount(searchResponse,10L);
searchResponse = client().prepareSearch("test")
.setQuery(QueryBuilders.rangeQuery("date_field").gte("Di,05 Dez 2000 02:55:00 -0800").lte("Fr,08 Dez 2000 00:00:00 -0800"))
.execute().actionGet();
assertHitCount(searchResponse,20L);
}
}
项目:elasticsearch_my
文件:TransportBulkActionTookTests.java
private void runTestTook(boolean controlled) throws Exception {
String bulkAction = copyToStringFromClasspath("/org/elasticsearch/action/bulk/simple-bulk.json");
// translate Windows line endings (\r\n) to standard ones (\n)
if (Constants.WINDOWS) {
bulkAction = Strings.replace(bulkAction,"\r\n","\n");
}
BulkRequest bulkRequest = new BulkRequest();
bulkRequest.add(bulkAction.getBytes(StandardCharsets.UTF_8),bulkAction.length(),XContentType.JSON);
AtomicLong expected = new AtomicLong();
TransportBulkAction action = createAction(controlled,expected);
action.doExecute(null,bulkRequest,new ActionListener<BulkResponse>() {
@Override
public void onResponse(BulkResponse bulkItemResponses) {
if (controlled) {
assertthat(
bulkItemResponses.getTook().getMillis(),equalTo(TimeUnit.MILLISECONDS.convert(expected.get(),TimeUnit.NANOSECONDS)));
} else {
assertthat(
bulkItemResponses.getTook().getMillis(),greaterThanorEqualTo(TimeUnit.MILLISECONDS.convert(expected.get(),TimeUnit.NANOSECONDS)));
}
}
@Override
public void onFailure(Exception e) {
}
});
}
项目:elasticsearch_my
文件:LambdaTests.java
public void testReturnVoidDef() {
assumeFalse("JDK is JDK 9",Constants.JRE_IS_MINIMUM_JAVA9);
// If we can catch the error at compile time we do
Exception expected = expectScriptThrows(ClassCastException.class,() -> {
exec("StringBuilder b = new StringBuilder(); def l = [1,2]; l.stream().mapToLong(i -> b.setLength(i))");
});
assertthat(expected.getMessage(),containsstring("Cannot cast from [void] to [def]."));
// Otherwise we convert the void into a null
assertEquals(Arrays.asList(null,null),exec("def b = new StringBuilder(); def l = [1,2]; l.stream().map(i -> b.setLength(i)).collect(Collectors.toList())"));
assertEquals(Arrays.asList(null,exec("def b = new StringBuilder(); List l = [1,2]; l.stream().map(i -> b.setLength(i)).collect(Collectors.toList())"));
}
项目:elasticsearch_my
文件:FunctionRefTests.java
public void testClassMissing() {
assumeFalse("JDK is JDK 9",Constants.JRE_IS_MINIMUM_JAVA9);
Exception e = expectScriptThrows(IllegalArgumentException.class,() -> {
exec("List l = [2,1]; l.sort(Bogus::bogus); return l.get(0);",false);
});
assertthat(e.getMessage(),endsWith("Variable [Bogus] is not defined."));
}
项目:elasticsearch_my
文件:FunctionRefTests.java
public void testQualifiedClassMissing() {
assumeFalse("JDK is JDK 9",1]; l.sort(org.joda.time.BogusDateTime::bogus); return l.get(0);",false);
});
/* Because the type isn't kNown and we use the lexer hack this fails to parse. I find this error message confusing but it is the one
* we have... */
assertEquals("invalid sequence of tokens near ['::'].",e.getMessage());
}
static void bsdImpl() {
boolean supported = Constants.FREE_BSD || OPENBSD || Constants.MAC_OS_X;
if (supported == false) {
throw new IllegalStateException("bug: should not be trying to initialize RLIMIT_NPROC for an unsupported OS");
}
JNACLibrary.Rlimit limit = new JNACLibrary.Rlimit();
limit.rlim_cur.setValue(0);
limit.rlim_max.setValue(0);
if (JNACLibrary.setrlimit(RLIMIT_NPROC,limit) != 0) {
throw new UnsupportedOperationException("RLIMIT_NPROC unavailable: " + JNACLibrary.strerror(Native.getLastError()));
}
logger.debug("BSD RLIMIT_NPROC initialization successful");
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。