forked from apache/calcite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added unit test and refined implementation
- Loading branch information
1 parent
a844cde
commit 8a2a130
Showing
2 changed files
with
229 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
plus/src/test/java/org/apache/calcite/adapter/os/PsTableFunctionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to you under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.calcite.adapter.os; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
/** | ||
* Unit tests for the ps (process status) table function. | ||
*/ | ||
class PsTableFunctionTest { | ||
|
||
@Test void testPsInfoParsing() { | ||
final List<String> input = new ArrayList<>(); | ||
input.add("startup user 56399 1 56399 0 S 0.0 0.0 410348128 6672 ??" | ||
+ " 3:25PM 0:00.22 501 501 0 /usr/lib exec/trustd"); | ||
input.add("root 1 107 107 0 Ss 0.0 0.0 410142784 4016 ??" | ||
+ " 11Apr24 0:52.32 0 0 0 " | ||
+ "/System/Library/PrivateFrameworks/Uninstall.framework/Resources/uninstalld"); | ||
input.add("user.name 1 1661 1661 0 S 0.7 0.2 412094800 75232 ?? " | ||
+ "11Apr24 325:33.63 775020228 775020228 0 " | ||
+ "/System/Library/CoreServices/ControlCenter app/Contents/MacOS/ControlCenter"); | ||
|
||
final List<List<Object>> output = | ||
ImmutableList.of( | ||
Arrays.asList("startup user", 56399, 1, 56399, 0, "S", 0, 0, "410348128", "6672", "??", | ||
"3:25PM", 220L, "501", "501", "0", "/usr/lib exec/trustd"), | ||
Arrays.asList("root", 1, 107, 107, 0, "Ss", 0, 0, "410142784", "4016", "??", | ||
"11Apr24", 52320L, "0", "0", "0", | ||
"/System/Library/PrivateFrameworks/Uninstall.framework/Resources/uninstalld"), | ||
Arrays.asList("user.name", 1, 1661, 1661, 0, "S", 7, 2, "412094800", "75232", "??", | ||
"11Apr24", 19533630L, "775020228", "775020228", "0", | ||
"/System/Library/CoreServices/ControlCenter app/Contents/MacOS/ControlCenter")); | ||
|
||
final Map<String, List<Object>> testValues = new HashMap<>(); | ||
for (int i = 0; i < input.size(); i++) { | ||
testValues.put(input.get(i), output.get(i)); | ||
} | ||
|
||
final PsTableFunction.LineParser psLineParser = new PsTableFunction.LineParser(); | ||
for (Map.Entry<String, List<Object>> e : testValues.entrySet()) { | ||
assertThat(psLineParser.apply(e.getKey()), is(e.getValue().toArray())); | ||
} | ||
} | ||
} |