forked from D-Net/dnet-hadoop
fixed a compilation problem of a unit test
This commit is contained in:
parent
172363e7f1
commit
c4fce785ab
|
@ -45,7 +45,8 @@ public class GenerateNotificationsJob {
|
||||||
|
|
||||||
final ArgumentApplicationParser parser = new ArgumentApplicationParser(
|
final ArgumentApplicationParser parser = new ArgumentApplicationParser(
|
||||||
IOUtils
|
IOUtils
|
||||||
.toString(GenerateNotificationsJob.class
|
.toString(
|
||||||
|
GenerateNotificationsJob.class
|
||||||
.getResourceAsStream("/eu/dnetlib/dhp/broker/oa/generate_notifications.json")));
|
.getResourceAsStream("/eu/dnetlib/dhp/broker/oa/generate_notifications.json")));
|
||||||
parser.parseArgument(args);
|
parser.parseArgument(args);
|
||||||
|
|
||||||
|
@ -79,7 +80,10 @@ public class GenerateNotificationsJob {
|
||||||
final Encoder<Notification> nEncoder = Encoders.bean(Notification.class);
|
final Encoder<Notification> nEncoder = Encoders.bean(Notification.class);
|
||||||
final Dataset<Notification> notifications = ClusterUtils
|
final Dataset<Notification> notifications = ClusterUtils
|
||||||
.readPath(spark, eventsPath, Event.class)
|
.readPath(spark, eventsPath, Event.class)
|
||||||
.map((MapFunction<Event, NotificationGroup>) e -> generateNotifications(e, subscriptions, conditionsMap, startTime), ngEncoder)
|
.map(
|
||||||
|
(MapFunction<Event, NotificationGroup>) e -> generateNotifications(
|
||||||
|
e, subscriptions, conditionsMap, startTime),
|
||||||
|
ngEncoder)
|
||||||
.flatMap((FlatMapFunction<NotificationGroup, Notification>) g -> g.getData().iterator(), nEncoder);
|
.flatMap((FlatMapFunction<NotificationGroup, Notification>) g -> g.getData().iterator(), nEncoder);
|
||||||
|
|
||||||
ClusterUtils.save(notifications, notificationsPath, Notification.class, total);
|
ClusterUtils.save(notifications, notificationsPath, Notification.class, total);
|
||||||
|
@ -99,7 +103,8 @@ public class GenerateNotificationsJob {
|
||||||
final long date) {
|
final long date) {
|
||||||
final List<Notification> list = subscriptions
|
final List<Notification> list = subscriptions
|
||||||
.stream()
|
.stream()
|
||||||
.filter(s -> StringUtils.isBlank(s.getTopic()) || s.getTopic().equals("*") || s.getTopic().equals(e.getTopic()))
|
.filter(
|
||||||
|
s -> StringUtils.isBlank(s.getTopic()) || s.getTopic().equals("*") || s.getTopic().equals(e.getTopic()))
|
||||||
.filter(s -> verifyConditions(e.getMap(), conditionsMap.get(s.getSubscriptionId())))
|
.filter(s -> verifyConditions(e.getMap(), conditionsMap.get(s.getSubscriptionId())))
|
||||||
.map(s -> generateNotification(s, e, date))
|
.map(s -> generateNotification(s, e, date))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
@ -130,14 +135,17 @@ public class GenerateNotificationsJob {
|
||||||
|
|
||||||
if (conditions.containsKey("trust")
|
if (conditions.containsKey("trust")
|
||||||
&& !SubscriptionUtils
|
&& !SubscriptionUtils
|
||||||
.verifyFloatRange(map.getTrust(), conditions.get("trust").get(0).getValue(), conditions.get("trust").get(0).getOtherValue())) {
|
.verifyFloatRange(
|
||||||
|
map.getTrust(), conditions.get("trust").get(0).getValue(),
|
||||||
|
conditions.get("trust").get(0).getOtherValue())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (conditions.containsKey("targetDateofacceptance") && !conditions
|
if (conditions.containsKey("targetDateofacceptance") && !conditions
|
||||||
.get("targetDateofacceptance")
|
.get("targetDateofacceptance")
|
||||||
.stream()
|
.stream()
|
||||||
.anyMatch(c -> SubscriptionUtils
|
.anyMatch(
|
||||||
|
c -> SubscriptionUtils
|
||||||
.verifyDateRange(map.getTargetDateofacceptance(), c.getValue(), c.getOtherValue()))) {
|
.verifyDateRange(map.getTargetDateofacceptance(), c.getValue(), c.getOtherValue()))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,8 @@ public class IndexNotificationsJob {
|
||||||
|
|
||||||
final ArgumentApplicationParser parser = new ArgumentApplicationParser(
|
final ArgumentApplicationParser parser = new ArgumentApplicationParser(
|
||||||
IOUtils
|
IOUtils
|
||||||
.toString(IndexNotificationsJob.class
|
.toString(
|
||||||
|
IndexNotificationsJob.class
|
||||||
.getResourceAsStream("/eu/dnetlib/dhp/broker/oa/index_notifications.json")));
|
.getResourceAsStream("/eu/dnetlib/dhp/broker/oa/index_notifications.json")));
|
||||||
parser.parseArgument(args);
|
parser.parseArgument(args);
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ import eu.dnetlib.dhp.broker.model.MappedFields;
|
||||||
import eu.dnetlib.dhp.broker.model.Subscription;
|
import eu.dnetlib.dhp.broker.model.Subscription;
|
||||||
import eu.dnetlib.dhp.broker.oa.util.NotificationGroup;
|
import eu.dnetlib.dhp.broker.oa.util.NotificationGroup;
|
||||||
|
|
||||||
class IndexNotificationsJobTest {
|
class GenerateNotificationsJobTest {
|
||||||
|
|
||||||
private List<Subscription> subscriptions;
|
private List<Subscription> subscriptions;
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ class IndexNotificationsJobTest {
|
||||||
.setConditions(
|
.setConditions(
|
||||||
"[{\"field\":\"targetDatasourceName\",\"fieldType\":\"STRING\",\"operator\":\"EXACT\",\"listParams\":[{\"value\":\"reposiTUm\"}]},{\"field\":\"trust\",\"fieldType\":\"FLOAT\",\"operator\":\"RANGE\",\"listParams\":[{\"value\":\"0\",\"otherValue\":\"1\"}]}]");
|
"[{\"field\":\"targetDatasourceName\",\"fieldType\":\"STRING\",\"operator\":\"EXACT\",\"listParams\":[{\"value\":\"reposiTUm\"}]},{\"field\":\"trust\",\"fieldType\":\"FLOAT\",\"operator\":\"RANGE\",\"listParams\":[{\"value\":\"0\",\"otherValue\":\"1\"}]}]");
|
||||||
subscriptions = Arrays.asList(s);
|
subscriptions = Arrays.asList(s);
|
||||||
conditionsMap = IndexNotificationsJob.prepareConditionsMap(subscriptions);
|
conditionsMap = GenerateNotificationsJob.prepareConditionsMap(subscriptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -40,7 +40,7 @@ class IndexNotificationsJobTest {
|
||||||
final Event event = new Event();
|
final Event event = new Event();
|
||||||
event.setTopic("ENRICH/MISSING/PROJECT");
|
event.setTopic("ENRICH/MISSING/PROJECT");
|
||||||
|
|
||||||
final NotificationGroup res = IndexNotificationsJob
|
final NotificationGroup res = GenerateNotificationsJob
|
||||||
.generateNotifications(event, subscriptions, conditionsMap, 0);
|
.generateNotifications(event, subscriptions, conditionsMap, 0);
|
||||||
assertEquals(0, res.getData().size());
|
assertEquals(0, res.getData().size());
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ class IndexNotificationsJobTest {
|
||||||
event.getMap().setTargetDatasourceName("reposiTUm");
|
event.getMap().setTargetDatasourceName("reposiTUm");
|
||||||
event.getMap().setTrust(0.8f);
|
event.getMap().setTrust(0.8f);
|
||||||
|
|
||||||
final NotificationGroup res = IndexNotificationsJob
|
final NotificationGroup res = GenerateNotificationsJob
|
||||||
.generateNotifications(event, subscriptions, conditionsMap, 0);
|
.generateNotifications(event, subscriptions, conditionsMap, 0);
|
||||||
assertEquals(1, res.getData().size());
|
assertEquals(1, res.getData().size());
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ class IndexNotificationsJobTest {
|
||||||
event.getMap().setTargetDatasourceName("Puma");
|
event.getMap().setTargetDatasourceName("Puma");
|
||||||
event.getMap().setTrust(0.8f);
|
event.getMap().setTrust(0.8f);
|
||||||
|
|
||||||
final NotificationGroup res = IndexNotificationsJob
|
final NotificationGroup res = GenerateNotificationsJob
|
||||||
.generateNotifications(event, subscriptions, conditionsMap, 0);
|
.generateNotifications(event, subscriptions, conditionsMap, 0);
|
||||||
assertEquals(0, res.getData().size());
|
assertEquals(0, res.getData().size());
|
||||||
}
|
}
|
||||||
|
@ -77,11 +77,11 @@ class IndexNotificationsJobTest {
|
||||||
event.setTopic("ENRICH/MISSING/PROJECT");
|
event.setTopic("ENRICH/MISSING/PROJECT");
|
||||||
|
|
||||||
// warm up
|
// warm up
|
||||||
IndexNotificationsJob.generateNotifications(event, subscriptions, conditionsMap, 0);
|
GenerateNotificationsJob.generateNotifications(event, subscriptions, conditionsMap, 0);
|
||||||
|
|
||||||
final long start = System.currentTimeMillis();
|
final long start = System.currentTimeMillis();
|
||||||
for (int i = 0; i < N_TIMES; i++) {
|
for (int i = 0; i < N_TIMES; i++) {
|
||||||
IndexNotificationsJob.generateNotifications(event, subscriptions, conditionsMap, 0);
|
GenerateNotificationsJob.generateNotifications(event, subscriptions, conditionsMap, 0);
|
||||||
}
|
}
|
||||||
final long end = System.currentTimeMillis();
|
final long end = System.currentTimeMillis();
|
||||||
System.out
|
System.out
|
||||||
|
@ -98,11 +98,11 @@ class IndexNotificationsJobTest {
|
||||||
event.getMap().setTrust(0.8f);
|
event.getMap().setTrust(0.8f);
|
||||||
|
|
||||||
// warm up
|
// warm up
|
||||||
IndexNotificationsJob.generateNotifications(event, subscriptions, conditionsMap, 0);
|
GenerateNotificationsJob.generateNotifications(event, subscriptions, conditionsMap, 0);
|
||||||
|
|
||||||
final long start = System.currentTimeMillis();
|
final long start = System.currentTimeMillis();
|
||||||
for (int i = 0; i < N_TIMES; i++) {
|
for (int i = 0; i < N_TIMES; i++) {
|
||||||
IndexNotificationsJob.generateNotifications(event, subscriptions, conditionsMap, 0);
|
GenerateNotificationsJob.generateNotifications(event, subscriptions, conditionsMap, 0);
|
||||||
}
|
}
|
||||||
final long end = System.currentTimeMillis();
|
final long end = System.currentTimeMillis();
|
||||||
System.out
|
System.out
|
||||||
|
@ -118,11 +118,11 @@ class IndexNotificationsJobTest {
|
||||||
event.getMap().setTrust(0.8f);
|
event.getMap().setTrust(0.8f);
|
||||||
|
|
||||||
// warm up
|
// warm up
|
||||||
IndexNotificationsJob.generateNotifications(event, subscriptions, conditionsMap, 0);
|
GenerateNotificationsJob.generateNotifications(event, subscriptions, conditionsMap, 0);
|
||||||
|
|
||||||
final long start = System.currentTimeMillis();
|
final long start = System.currentTimeMillis();
|
||||||
for (int i = 0; i < N_TIMES; i++) {
|
for (int i = 0; i < N_TIMES; i++) {
|
||||||
IndexNotificationsJob.generateNotifications(event, subscriptions, conditionsMap, 0);
|
GenerateNotificationsJob.generateNotifications(event, subscriptions, conditionsMap, 0);
|
||||||
}
|
}
|
||||||
final long end = System.currentTimeMillis();
|
final long end = System.currentTimeMillis();
|
||||||
System.out
|
System.out
|
Loading…
Reference in New Issue