-
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
base: master
Are you sure you want to change the base?
Changes from 8 commits
70e84a1
9145156
d0e1345
70d1fbf
e8a9fce
b3ef470
08337c1
8b28adc
122b228
04c9cf3
73e1cee
af2a3d9
024d545
5d57792
da22f9c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,5 +71,4 @@ public Object execute() { | |
| public Object execute(Object o) { | ||
| return null; | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| /* | ||
| * 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; | ||
|
|
||
| @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(); | ||
| 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() { | ||
| File resourcesDirectory = new File("src/test/resources/"); | ||
|
||
| String resourcedir = "/Testing_Data_1_3dayLog+Meta+Onto/"; | ||
| String dataDir = resourcesDirectory.getAbsolutePath() + resourcedir; | ||
| return dataDir; | ||
| } | ||
|
|
||
| @Test | ||
| public void testPreprocess() throws IOException { | ||
| weblogEngine.preprocess(); | ||
| testPreprocessUserHistory(); | ||
| testPreprocessClickStream(); | ||
| } | ||
|
|
||
| private void testPreprocessUserHistory() throws IOException { | ||
| // compare user history data | ||
| String userHistorycsvFile = getTestDataPath() + "/userHistoryMatrix.csv"; | ||
| 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() + "/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++) { | ||
| int value = Integer.parseInt(str[j]); | ||
| if (value > 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; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| /* | ||
| * 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", "MurdorES").put("http.enabled", "false").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()); | ||
| } | ||
|
|
||
| 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. |
||
| } | ||
|
|
||
| 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); | ||
| } | ||
| } | ||
| } | ||
| 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
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /* | ||
| * 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.main; | ||
lewismc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| import org.apache.sdap.mudrod.driver.EmbeddedElasticsearchServer; | ||
| import org.apache.sdap.mudrod.driver.EmbeddedElasticsearchServer; | ||
| import org.elasticsearch.client.Client; | ||
| import org.junit.After; | ||
| import org.junit.AfterClass; | ||
| import org.junit.Before; | ||
| import org.junit.BeforeClass; | ||
|
|
||
| /** | ||
| * This is a helper class the starts an embedded elasticsearch server for each | ||
|
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. We do not need to start a new server for every test. We need to start one server which runs for the duration of the tests. Between tests, the data within the server should probably be deleted/truncated. This however depends on what tests you are running. 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. I tried to add an Embedded Elasticsearch engine as you suggested. I found a solution from internet with the three files 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. Once you have addressed the comments here fully I will test the code locally and provide input as to why it is not working. |
||
| * test. | ||
| */ | ||
| public abstract class AbstractElasticsearchIntegrationTest { | ||
|
|
||
| private static EmbeddedElasticsearchServer embeddedElasticsearchServer; | ||
|
|
||
| @BeforeClass | ||
| public static void startEmbeddedElasticsearchServer() { | ||
| embeddedElasticsearchServer = new EmbeddedElasticsearchServer(); | ||
| } | ||
|
|
||
| @AfterClass | ||
| public static void shutdownEmbeddedElasticsearchServer() { | ||
| embeddedElasticsearchServer.shutdown(); | ||
| } | ||
|
|
||
| /** | ||
| * By using this method you can access the embedded server. | ||
| */ | ||
| protected Client getClient() { | ||
| return embeddedElasticsearchServer.getClient(); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is buggy. We just want to throw the Exception... not continuously print the help arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@quintinali please address this. It should not throw help. It should through the
Exception eThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lewismc In my computer, the old code (
formatter.printHelp("MudrodEngine: 'dataDir' argument is mandatory. " + "User must also provide an ingest method.", true)) comes with an error “The method printHelp(String, Options) in the type HelpFormatter is not applicable for the arguments (String, boolean)”
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK what I am saying is that this code should be changed to the following
...or something similar.