2020-04-02 18:37:53 +02:00
|
|
|
package eu.dnetlib.dhp.oa.dedup;
|
2020-04-01 18:48:31 +02:00
|
|
|
|
2020-04-02 18:37:53 +02:00
|
|
|
import eu.dnetlib.dhp.application.ArgumentApplicationParser;
|
2020-04-01 18:48:31 +02:00
|
|
|
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
|
2020-04-02 18:37:53 +02:00
|
|
|
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
|
2020-04-03 18:32:25 +02:00
|
|
|
import net.bytebuddy.utility.RandomString;
|
|
|
|
import org.apache.commons.io.FileUtils;
|
2020-04-01 18:48:31 +02:00
|
|
|
import org.apache.commons.io.IOUtils;
|
2020-04-03 18:32:25 +02:00
|
|
|
import org.apache.spark.SparkConf;
|
|
|
|
import org.apache.spark.sql.SparkSession;
|
2020-04-01 18:48:31 +02:00
|
|
|
import org.dom4j.DocumentException;
|
2020-04-03 18:32:25 +02:00
|
|
|
import org.junit.jupiter.api.*;
|
2020-04-02 18:37:53 +02:00
|
|
|
import org.junit.jupiter.api.extension.ExtendWith;
|
2020-04-01 18:48:31 +02:00
|
|
|
import org.mockito.Mock;
|
2020-04-02 18:37:53 +02:00
|
|
|
import org.mockito.Mockito;
|
2020-04-01 19:05:48 +02:00
|
|
|
import org.mockito.junit.jupiter.MockitoExtension;
|
2020-04-01 18:48:31 +02:00
|
|
|
|
2020-04-03 18:32:25 +02:00
|
|
|
import java.io.File;
|
2020-04-01 18:48:31 +02:00
|
|
|
import java.io.IOException;
|
2020-04-03 18:32:25 +02:00
|
|
|
import java.net.URISyntaxException;
|
|
|
|
import java.nio.file.Paths;
|
2020-04-01 18:48:31 +02:00
|
|
|
|
2020-04-01 19:05:48 +02:00
|
|
|
import static org.mockito.Mockito.when;
|
2020-04-03 18:32:25 +02:00
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
2020-04-01 19:05:48 +02:00
|
|
|
|
|
|
|
@ExtendWith(MockitoExtension.class)
|
2020-04-03 18:32:25 +02:00
|
|
|
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
2020-04-01 18:48:31 +02:00
|
|
|
public class SparkDedupTest {
|
|
|
|
|
2020-04-03 18:32:25 +02:00
|
|
|
@Mock
|
|
|
|
ISLookUpService isLookUpService;
|
2020-04-01 18:48:31 +02:00
|
|
|
|
2020-04-03 18:32:25 +02:00
|
|
|
SparkSession spark;
|
2020-04-01 18:48:31 +02:00
|
|
|
|
2020-04-03 18:32:25 +02:00
|
|
|
static String testGraphBasePath;
|
|
|
|
static String testOutputBasePath;
|
|
|
|
String testActionSetId = "test-orchestrator";
|
2020-04-02 18:37:53 +02:00
|
|
|
|
2020-04-03 18:32:25 +02:00
|
|
|
@BeforeEach
|
|
|
|
public void setUp() throws IOException, ISLookUpException, DocumentException, URISyntaxException {
|
|
|
|
|
|
|
|
testGraphBasePath = Paths.get(getClass().getResource("/eu/dnetlib/dhp/dedup/entities").toURI()).toFile().getAbsolutePath();
|
|
|
|
testOutputBasePath = "/tmp/" + RandomString.make(5).toLowerCase();
|
|
|
|
spark = SparkSession
|
|
|
|
.builder()
|
|
|
|
.appName(SparkCreateSimRels.class.getSimpleName())
|
|
|
|
.master("local[*]")
|
|
|
|
.config(new SparkConf())
|
|
|
|
.getOrCreate();
|
|
|
|
|
|
|
|
when(isLookUpService.getResourceProfileByQuery(Mockito.contains(testActionSetId)))
|
2020-04-02 18:37:53 +02:00
|
|
|
.thenReturn(IOUtils.toString(getClass().getResourceAsStream("/eu/dnetlib/dhp/dedup/profiles/mock_orchestrator.xml")));
|
|
|
|
|
|
|
|
when(isLookUpService.getResourceProfileByQuery(Mockito.contains("organization")))
|
|
|
|
.thenReturn(IOUtils.toString(getClass().getResourceAsStream("/eu/dnetlib/dhp/dedup/conf/org.curr.conf.json")));
|
2020-04-01 18:48:31 +02:00
|
|
|
|
2020-04-02 18:37:53 +02:00
|
|
|
when(isLookUpService.getResourceProfileByQuery(Mockito.contains("publication")))
|
|
|
|
.thenReturn(IOUtils.toString(getClass().getResourceAsStream("/eu/dnetlib/dhp/dedup/conf/pub.curr.conf.json")));
|
2020-04-01 18:48:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-04-03 18:32:25 +02:00
|
|
|
@Order(1)
|
2020-04-01 18:48:31 +02:00
|
|
|
public void createSimRelsTest() throws Exception {
|
2020-04-02 18:37:53 +02:00
|
|
|
|
|
|
|
ArgumentApplicationParser parser = new ArgumentApplicationParser(
|
|
|
|
IOUtils.toString(
|
|
|
|
SparkCreateSimRels.class.getResourceAsStream("/eu/dnetlib/dhp/oa/dedup/createSimRels_parameters.json")));
|
|
|
|
parser.parseArgument(new String[]{
|
2020-04-01 18:48:31 +02:00
|
|
|
"-mt", "local[*]",
|
2020-04-03 18:32:25 +02:00
|
|
|
"-i", testGraphBasePath,
|
|
|
|
"-asi", testActionSetId,
|
2020-04-01 18:48:31 +02:00
|
|
|
"-la", "lookupurl",
|
2020-04-03 18:32:25 +02:00
|
|
|
"-w", testOutputBasePath});
|
|
|
|
|
|
|
|
new SparkCreateSimRels(parser, spark).run(isLookUpService);
|
|
|
|
|
|
|
|
//test number of simrels
|
|
|
|
long orgs_simrel = spark.read().load(testOutputBasePath + "/" + testActionSetId + "/organization_simrel").count();
|
|
|
|
long pubs_simrel = spark.read().load(testOutputBasePath + "/" + testActionSetId + "/publication_simrel").count();
|
2020-04-02 18:37:53 +02:00
|
|
|
|
2020-04-03 18:32:25 +02:00
|
|
|
assertEquals(918, orgs_simrel);
|
|
|
|
assertEquals(0, pubs_simrel);
|
2020-04-02 18:37:53 +02:00
|
|
|
|
2020-04-01 18:48:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// @Disabled("must be parametrized to run locally")
|
|
|
|
// public void createCCTest() throws Exception {
|
|
|
|
//
|
|
|
|
// SparkCreateConnectedComponent.main(new String[]{
|
|
|
|
// "-mt", "local[*]",
|
|
|
|
// "-s", "/Users/miconis/dumps",
|
|
|
|
// "-e", entity,
|
|
|
|
// "-c", ArgumentApplicationParser.compressArgument(configuration),
|
|
|
|
// "-t", "/tmp/dedup",
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// @Disabled("must be parametrized to run locally")
|
|
|
|
// public void dedupRecordTest() throws Exception {
|
|
|
|
// SparkCreateDedupRecord.main(new String[]{
|
|
|
|
// "-mt", "local[*]",
|
|
|
|
// "-s", "/Users/miconis/dumps",
|
|
|
|
// "-e", entity,
|
|
|
|
// "-c", ArgumentApplicationParser.compressArgument(configuration),
|
|
|
|
// "-d", "/tmp/dedup",
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// @Disabled("must be parametrized to run locally")
|
|
|
|
// public void printConfiguration() throws Exception {
|
|
|
|
// System.out.println(ArgumentApplicationParser.compressArgument(configuration));
|
2020-04-03 18:32:25 +02:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// @Disabled("must be parametrized to run locally")
|
|
|
|
// public void testHashCode() {
|
|
|
|
// final String s1 = "20|grid________::6031f94bef015a37783268ec1e75f17f";
|
|
|
|
// final String s2 = "20|nsf_________::b12be9edf414df8ee66b4c52a2d8da46";
|
|
|
|
//
|
|
|
|
// final HashFunction hashFunction = Hashing.murmur3_128();
|
|
|
|
//
|
|
|
|
// System.out.println(s1.hashCode());
|
|
|
|
// System.out.println(hashFunction.hashString(s1).asLong());
|
|
|
|
// System.out.println(s2.hashCode());
|
|
|
|
// System.out.println(hashFunction.hashString(s2).asLong());
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// public List<DedupConfig> prepareConfigurations() throws IOException {
|
|
|
|
//
|
|
|
|
// return Lists.newArrayList(
|
|
|
|
// DedupConfig.load(IOUtils.toString(getClass().getResourceAsStream("/eu/dnetlib/dhp/dedup/conf/org.curr.conf.json"))),
|
|
|
|
// DedupConfig.load(IOUtils.toString(getClass().getResourceAsStream("/eu/dnetlib/dhp/dedup/conf/org.curr.conf.json")))
|
|
|
|
// );
|
2020-04-01 18:48:31 +02:00
|
|
|
// }
|
|
|
|
|
2020-04-03 18:32:25 +02:00
|
|
|
@AfterAll
|
|
|
|
public static void cleanUp() throws IOException {
|
|
|
|
FileUtils.deleteDirectory(new File(testOutputBasePath));
|
2020-04-02 18:37:53 +02:00
|
|
|
}
|
2020-04-01 18:48:31 +02:00
|
|
|
}
|