下面列出了org.apache.commons.lang.SystemUtils#IS_OS_LINUX 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Test
public void testMakeFileForPath() throws Exception {
assertNull(ModelUtils.makeFileForPath(null));
assertNull(ModelUtils.makeFileForPath(""));
assertEquals(new File((File) null, "/some/who/files/2012-11-02 13.47.10.jpg").getCanonicalPath(), ModelUtils.makeFileForPath("file:///some/who/files/2012-11-02 13.47.10.jpg").getAbsolutePath());
assertEquals(new File((File) null, "/some/who/files/2012-11-02 13.47.10.jpg").getCanonicalPath(), ModelUtils.makeFileForPath("file:///some/who/files/2012-11-02%2013.47.10.jpg").getAbsolutePath());
assertEquals(new File((File) null, "/some/who/files/main.c++").getCanonicalPath(), ModelUtils.makeFileForPath("file:///some/who/files/main.c++").getAbsolutePath());
assertEquals(new File((File) null, "/some/folder/temp/").getCanonicalPath(), ModelUtils.makeFileForPath("file:///some/folder/temp/").getAbsolutePath());
if (SystemUtils.IS_OS_LINUX) {
assertEquals(new File((File) null, "/some/folder/temp/ :<>?").getCanonicalPath(), ModelUtils.makeFileForPath("file:///some/folder/temp/ :<>?").getAbsolutePath());
assertEquals(new File((File) null, "/some/folder&ssd/temp/ :<>?test=jks&lls=1").getCanonicalPath(), ModelUtils.makeFileForPath("file:///some/folder&ssd/temp/ :<>?test=jks&lls=1").getAbsolutePath());
}
assertEquals("src/main/java/com/igormaznitsa/nbmindmap/nb/QuickSearchProvider.java".replace('/', File.separatorChar), ModelUtils.makeFileForPath("src/main/java/com/igormaznitsa/nbmindmap/nb/QuickSearchProvider.java").getPath());
}
public static Process createProcess(String command) {
ProcessBuilder processBuilder = new ProcessBuilder();
processBuilder.redirectErrorStream(true);
Process process = null;
try {
if (SystemUtils.IS_OS_LINUX) {
processBuilder.command("bash", "-c", command);
} else if (SystemUtils.IS_OS_WINDOWS) {
processBuilder.command("cmd.exe", "-c", command);
}
process = processBuilder.start();
} catch (IOException e) {
System.out.println("New process could not be created: " + e.getLocalizedMessage());
}
return process;
}
private static CharSequence getOS() {
if (SystemUtils.IS_OS_LINUX) {
return "linux";
} else if (SystemUtils.IS_OS_WINDOWS) {
return "win32";
} else if (SystemUtils.IS_OS_MAC || SystemUtils.IS_OS_MAC_OSX) {
return "macosx";
} else {
throw new IllegalArgumentException("Unsupported OS");
}
}
static EventLoopGroup getDefaultEventLoopGroup(int numThreads) {
ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("DL-io-%s").build();
if (SystemUtils.IS_OS_LINUX) {
try {
return new EpollEventLoopGroup(numThreads, threadFactory);
} catch (Throwable t) {
LOG.warn("Could not use Netty Epoll event loop for bookie server:", t);
return new NioEventLoopGroup(numThreads, threadFactory);
}
} else {
return new NioEventLoopGroup(numThreads, threadFactory);
}
}
@Test
public void testAsURI_Linux_CreatedAsFile() throws Exception {
if (SystemUtils.IS_OS_LINUX) {
final Properties props = new Properties();
props.put("Kõik või", "tere");
final MMapURI uri = new MMapURI(null, new File("/Kõik/või/mitte/midagi.txt"), props);
assertEquals(new URI("file:///K%C3%B5ik/v%C3%B5i/mitte/midagi.txt?K%C3%B5ik+v%C3%B5i=tere"), uri.asURI());
assertEquals("tere", uri.getParameters().getProperty("Kõik või"));
assertEquals(new File("/Kõik/või/mitte/midagi.txt"), uri.asFile(null));
}
}
@Override
protected boolean isApplicable() {
final boolean nettyDoesSupportMacUnixSockets = SystemUtils.IS_OS_MAC_OSX &&
ComparableVersion.OS_VERSION.isGreaterThanOrEqualTo("10.12");
return SystemUtils.IS_OS_LINUX || nettyDoesSupportMacUnixSockets;
}
@Override
public EventLoopGroup init(Bootstrap bootstrap, DockerClientConfig dockerClientConfig) {
if (SystemUtils.IS_OS_LINUX) {
return epollGroup();
} else if (SystemUtils.IS_OS_MAC_OSX) {
return kqueueGroup();
}
throw new RuntimeException("Unsupported OS");
}
@Override
protected boolean isApplicable() {
return "tcp".equalsIgnoreCase(config.getDockerHost().getScheme()) || SystemUtils.IS_OS_LINUX;
}
@Test (timeout = 10000)
public void testBasicCounters() throws Exception {
TezConfiguration tezconf = new TezConfiguration(defaultConf);
MockTezClient tezClient = new MockTezClient("testMockAM", tezconf, true, null, null, null,
null, false, false);
tezClient.start();
final String vAName = "A";
final String vBName = "B";
final String procCounterName = "Proc";
final String globalCounterName = "Global";
DAG dag = DAG.create("testBasicCounters");
Vertex vA = Vertex.create(vAName, ProcessorDescriptor.create("Proc.class"), 10);
Vertex vB = Vertex.create(vBName, ProcessorDescriptor.create("Proc.class"), 1);
dag.addVertex(vA)
.addVertex(vB)
.addEdge(
Edge.create(vA, vB, EdgeProperty.create(DataMovementType.SCATTER_GATHER,
DataSourceType.PERSISTED, SchedulingType.SEQUENTIAL,
OutputDescriptor.create("Out"), InputDescriptor.create("In"))));
TezCounters temp = new TezCounters();
temp.findCounter(new String(globalCounterName), new String(globalCounterName)).increment(1);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutput out = new DataOutputStream(bos);
temp.write(out);
final byte[] payload = bos.toByteArray();
MockDAGAppMaster mockApp = tezClient.getLocalClient().getMockApp();
MockContainerLauncher mockLauncher = mockApp.getContainerLauncher();
mockLauncher.startScheduling(false);
mockApp.countersDelegate = new CountersDelegate() {
@Override
public TezCounters getCounters(TaskSpec taskSpec) {
String vName = taskSpec.getVertexName();
TezCounters counters = new TezCounters();
final DataInputByteBuffer in = new DataInputByteBuffer();
in.reset(ByteBuffer.wrap(payload));
try {
// this ensures that the serde code path is covered.
// the internal merges of counters covers the constructor code path.
counters.readFields(in);
} catch (IOException e) {
Assert.fail(e.getMessage());
}
counters.findCounter(vName, procCounterName).increment(1);
for (OutputSpec output : taskSpec.getOutputs()) {
counters.findCounter(vName, output.getDestinationVertexName()).increment(1);
}
for (InputSpec input : taskSpec.getInputs()) {
counters.findCounter(vName, input.getSourceVertexName()).increment(1);
}
return counters;
}
};
mockApp.doSleep = false;
DAGClient dagClient = tezClient.submitDAG(dag);
mockLauncher.waitTillContainersLaunched();
DAGImpl dagImpl = (DAGImpl) mockApp.getContext().getCurrentDAG();
mockLauncher.startScheduling(true);
DAGStatus status = dagClient.waitForCompletion();
Assert.assertEquals(DAGStatus.State.SUCCEEDED, status.getState());
TezCounters counters = dagImpl.getAllCounters();
String osName = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
if (SystemUtils.IS_OS_LINUX) {
Assert.assertTrue(counters.findCounter(DAGCounter.AM_CPU_MILLISECONDS).getValue() > 0);
}
// verify processor counters
Assert.assertEquals(10, counters.findCounter(vAName, procCounterName).getValue());
Assert.assertEquals(1, counters.findCounter(vBName, procCounterName).getValue());
// verify edge counters
Assert.assertEquals(10, counters.findCounter(vAName, vBName).getValue());
Assert.assertEquals(1, counters.findCounter(vBName, vAName).getValue());
// verify global counters
Assert.assertEquals(11, counters.findCounter(globalCounterName, globalCounterName).getValue());
VertexImpl vAImpl = (VertexImpl) dagImpl.getVertex(vAName);
VertexImpl vBImpl = (VertexImpl) dagImpl.getVertex(vBName);
TezCounters vACounters = vAImpl.getAllCounters();
TezCounters vBCounters = vBImpl.getAllCounters();
String vACounterName = vACounters.findCounter(globalCounterName, globalCounterName).getName();
String vBCounterName = vBCounters.findCounter(globalCounterName, globalCounterName).getName();
if (vACounterName != vBCounterName) {
Assert.fail("String counter name objects dont match despite interning.");
}
CounterGroup vaGroup = vACounters.getGroup(globalCounterName);
String vaGrouName = vaGroup.getName();
CounterGroup vBGroup = vBCounters.getGroup(globalCounterName);
String vBGrouName = vBGroup.getName();
if (vaGrouName != vBGrouName) {
Assert.fail("String group name objects dont match despite interning.");
}
tezClient.stop();
}