-
Notifications
You must be signed in to change notification settings - Fork 14
SDAP-161 MUDROD embedded unit test #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
quintinali
wants to merge
15
commits into
apache:master
Choose a base branch
from
quintinali:SDAP-161
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
70e84a1
Merge remote-tracking branch 'refs/remotes/apache/master'
quintinali 9145156
Merge remote-tracking branch 'refs/remotes/apache/master'
quintinali d0e1345
add embedded elasticsearch engine
quintinali 70d1fbf
log preprocessing test case
quintinali e8a9fce
Merge remote-tracking branch 'refs/remotes/apache/master' into SDAP-161
quintinali b3ef470
test data for log preprocessing
quintinali 08337c1
modify code as request
quintinali 8b28adc
Solved most comments provided by the reviewer
quintinali 122b228
Revised code based on Lewis's comments
quintinali 04c9cf3
solved the embedded elasticsearch engine issue
quintinali 73e1cee
Merge remote-tracking branch 'refs/remotes/apache/master'
quintinali af2a3d9
Merge remote-tracking branch 'refs/remotes/apache/master'
quintinali 024d545
Fitting Bugs
supwar1 5d57792
Merge remote-tracking branch 'refs/remotes/origin/master' into SDAP-161
quintinali da22f9c
Fix bugs
quintinali File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -71,5 +71,4 @@ public Object execute() { | |
| public Object execute(Object o) { | ||
| return null; | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
129 changes: 129 additions & 0 deletions
129
core/src/test/java/org/apache/sdap/mudrod/discoveryengine/WeblogDiscoveryEngineTest.java
This file contains hidden or 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,129 @@ | ||
| /* | ||
| * Licensed 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.sdap.mudrod.discoveryengine; | ||
lewismc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| import java.io.BufferedReader; | ||
| import java.io.File; | ||
| import java.io.FileNotFoundException; | ||
| import java.io.FileReader; | ||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.LinkedList; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Properties; | ||
| import org.apache.sdap.mudrod.driver.ESDriver; | ||
| import org.apache.sdap.mudrod.driver.SparkDriver; | ||
| import org.apache.sdap.mudrod.main.AbstractElasticsearchIntegrationTest; | ||
| import org.apache.sdap.mudrod.main.MudrodConstants; | ||
| import org.apache.sdap.mudrod.main.MudrodEngine; | ||
| import org.junit.AfterClass; | ||
| import org.junit.Assert; | ||
| import org.junit.BeforeClass; | ||
| import org.junit.Test; | ||
|
|
||
| public class WeblogDiscoveryEngineTest extends AbstractElasticsearchIntegrationTest { | ||
|
|
||
| private static WeblogDiscoveryEngine weblogEngine = null; | ||
|
|
||
| static String DIR_TESTDATA_ONE = "Testing_Data_1_3dayLog+Meta+Onto"; | ||
|
|
||
| @BeforeClass | ||
| public static void setUp() { | ||
| MudrodEngine mudrodEngine = new MudrodEngine(); | ||
| Properties props = mudrodEngine.loadConfig(); | ||
| ESDriver es = new ESDriver(props); | ||
| SparkDriver spark = new SparkDriver(props); | ||
| String dataDir = getTestDataPath(DIR_TESTDATA_ONE); | ||
| System.out.println(dataDir); | ||
| props.setProperty(MudrodConstants.DATA_DIR, dataDir); | ||
| MudrodEngine.loadPathConfig(mudrodEngine, dataDir); | ||
| weblogEngine = new WeblogDiscoveryEngine(props, es, spark); | ||
| } | ||
|
|
||
| @AfterClass | ||
| public static void tearDown() { | ||
| } | ||
|
|
||
| private static String getTestDataPath(String testDataDir) { | ||
| String path = WeblogDiscoveryEngineTest.class.getClassLoader().getResource(testDataDir).toString(); | ||
| if(path.startsWith("file:/")){ | ||
| path = path.replaceAll("file:/", ""); | ||
| } | ||
| return path; | ||
| } | ||
|
|
||
| @Test | ||
| public void testPreprocess() throws IOException { | ||
| weblogEngine.preprocess(); | ||
| testPreprocessUserHistory(); | ||
| testPreprocessClickStream(); | ||
| } | ||
|
|
||
| private void testPreprocessUserHistory() throws IOException { | ||
| // compare user history data | ||
| String userHistorycsvFile = getTestDataPath(DIR_TESTDATA_ONE) + "/userHistoryMatrix.csv"; | ||
| System.out.println(userHistorycsvFile); | ||
| HashMap<String, List<String>> map = extractPairFromCSV(userHistorycsvFile); | ||
| Assert.assertEquals("failed in history data result!", "195.219.98.7", String.join(",", map.get("sea surface topography"))); | ||
| } | ||
|
|
||
| private void testPreprocessClickStream() throws IOException { | ||
| String clickStreamcsvFile = getTestDataPath(DIR_TESTDATA_ONE) + "/clickStreamMatrix.csv"; | ||
| System.out.println(clickStreamcsvFile); | ||
| HashMap<String, List<String>> map = extractPairFromCSV(clickStreamcsvFile); | ||
| System.out.println(map); | ||
| Assert.assertEquals("failed in click stream result!", "\"ostm_l2_ost_ogdr_gps\"", String.join(",", map.get("sea surface topography"))); | ||
| } | ||
|
|
||
| private HashMap extractPairFromCSV(String csvfile){ | ||
| BufferedReader br = null; | ||
| try { | ||
| br = new BufferedReader(new FileReader(csvfile)); | ||
| } catch (FileNotFoundException e) { | ||
| e.printStackTrace(); | ||
| } | ||
| String line = null; | ||
| HashMap<String, List<String>> map = new HashMap<>(); | ||
| int i = 0; | ||
| List<String> header = new LinkedList<>(); | ||
| try { | ||
| while ((line = br.readLine()) != null) { | ||
| if (i == 0) { | ||
| String str[] = line.split(","); | ||
| for (String s : str) { | ||
| header.add(s); | ||
| } | ||
| } else { | ||
| String str[] = line.split(","); | ||
| for (int j = 1; j < str.length; j++) { | ||
| double value = Double.parseDouble(str[j]); | ||
| if (value > 0.0) { | ||
| if (!map.containsKey(str[0])) { | ||
| map.put(str[0], new ArrayList<>()); | ||
| } | ||
| map.get(str[0]).add(header.get(j)); | ||
| } | ||
| } | ||
| } | ||
| i += 1; | ||
| } | ||
| } catch (IOException e) { | ||
| e.printStackTrace(); | ||
| } | ||
|
|
||
| return map; | ||
| } | ||
| } | ||
113 changes: 113 additions & 0 deletions
113
core/src/test/java/org/apache/sdap/mudrod/driver/EmbeddedElasticsearchServer.java
This file contains hidden or 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,113 @@ | ||
| /* | ||
| * Licensed 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.sdap.mudrod.driver; | ||
lewismc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| import org.apache.commons.io.FileUtils; | ||
| import org.elasticsearch.client.Client; | ||
| import org.elasticsearch.common.settings.Settings; | ||
| import org.elasticsearch.node.Node; | ||
| import org.elasticsearch.node.NodeValidationException; | ||
| import org.elasticsearch.transport.Netty3Plugin; | ||
|
|
||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.util.Arrays; | ||
| import java.util.Collection; | ||
|
|
||
| /** | ||
| * embedded elasticsearch server. | ||
| */ | ||
| public class EmbeddedElasticsearchServer { | ||
|
|
||
| private static final String DEFAULT_DATA_DIRECTORY = "target/elasticsearch-data"; | ||
|
|
||
| private Node node; | ||
| private final String dataDirectory; | ||
|
|
||
| public EmbeddedElasticsearchServer() { | ||
| this(DEFAULT_DATA_DIRECTORY); | ||
| } | ||
|
|
||
| public EmbeddedElasticsearchServer(String dataDirectory) { | ||
|
|
||
| this.dataDirectory = dataDirectory; | ||
|
|
||
| Settings.Builder settingsBuilder = Settings.builder(); | ||
| settingsBuilder.put("http.type", "netty3"); | ||
| settingsBuilder.put("transport.type", "netty3"); | ||
| settingsBuilder.put("cluster.name", "MudrodES").put("http.enabled", "true").put("path.data", dataDirectory).put("path.home", "/"); | ||
|
|
||
| Settings settings = settingsBuilder.build(); | ||
| Collection plugins = Arrays.asList(Netty3Plugin.class); | ||
| node = null; | ||
| try { | ||
| node = new PluginConfigurableNode(settings, plugins).start(); | ||
| System.out.println(node.toString()); | ||
| } catch (NodeValidationException e) { | ||
| e.printStackTrace(); | ||
| } | ||
|
|
||
| System.out.println(node.getNodeEnvironment().nodeId()); | ||
|
|
||
|
|
||
| /* System.out.println("======= INTEGRATION TEST: START Embedded Elasticsearch Server ========"); | ||
| Settings settings = Settings.builder().put("path.home", this.dataDirectory) | ||
| .put("transport.type", "local") | ||
| .put("network.host", "127.0.0.1") | ||
| .put("cluster.name", "MudrodES") | ||
| //.put("http.port", "9200-9300") | ||
| .put("http.type", "netty3") | ||
| //.put("transport.tcp.port", "9300-9400") | ||
| .put("http.enabled", false) | ||
| // .put("client.transport.sniff", true) | ||
| .build(); | ||
| node = new Node(settings); | ||
|
|
||
|
|
||
| Settings set = node.settings(); | ||
| try { | ||
| node.start(); | ||
| } catch (NodeValidationException e) { | ||
| // TODO Auto-generated catch block | ||
| e.printStackTrace(); | ||
| } | ||
|
|
||
| final String clusterName = node.settings().get("cluster.name"); | ||
| final String clusterport = node.settings().get("transport.tcp.port"); | ||
| System.out.println("starting server with cluster-name: "+ clusterport); | ||
|
|
||
| System.out.println(node.client());*/ | ||
|
|
||
| } | ||
|
|
||
| public Client getClient() { | ||
| return node.client(); | ||
| } | ||
|
|
||
| public void shutdown() { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you are not using the content of this method... remove it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this method if it has no content and you are not overriding anything. |
||
| try { | ||
| node.close(); | ||
| } catch (IOException e) { | ||
| e.printStackTrace(); | ||
| } | ||
| } | ||
|
|
||
| private void deleteDataDirectory() { | ||
| try { | ||
| FileUtils.deleteDirectory(new File(dataDirectory)); | ||
| } catch (IOException e) { | ||
| throw new RuntimeException("Could not delete data directory of embedded elasticsearch server", e); | ||
| } | ||
| } | ||
| } | ||
27 changes: 27 additions & 0 deletions
27
core/src/test/java/org/apache/sdap/mudrod/driver/PluginConfigurableNode.java
This file contains hidden or 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,27 @@ | ||
| /* | ||
| * Licensed 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.sdap.mudrod.driver; | ||
lewismc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| import java.util.Collection; | ||
|
|
||
| import org.elasticsearch.common.settings.Settings; | ||
| import org.elasticsearch.node.Node; | ||
| import org.elasticsearch.node.internal.InternalSettingsPreparer; | ||
| import org.elasticsearch.plugins.Plugin; | ||
|
|
||
| public class PluginConfigurableNode extends Node { | ||
| public PluginConfigurableNode(Settings settings, Collection<Class<? extends Plugin>> classpathPlugins) { | ||
| super(InternalSettingsPreparer.prepareEnvironment(settings, null), classpathPlugins); | ||
lewismc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.