1 |
33806
|
andrea.man
|
package eu.dnetlib.data.mdstore.modular.mongodb;
|
2 |
|
|
|
3 |
33870
|
andrea.man
|
import java.io.File;
|
4 |
|
|
import java.io.FileInputStream;
|
5 |
33806
|
andrea.man
|
import java.io.IOException;
|
6 |
|
|
import java.util.Iterator;
|
7 |
|
|
import java.util.UUID;
|
8 |
|
|
|
9 |
|
|
import org.apache.commons.io.IOUtils;
|
10 |
|
|
import org.junit.Ignore;
|
11 |
33870
|
andrea.man
|
import org.junit.Test;
|
12 |
33806
|
andrea.man
|
import org.junit.runner.RunWith;
|
13 |
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
14 |
|
|
import org.springframework.core.io.ClassPathResource;
|
15 |
|
|
import org.springframework.test.context.ContextConfiguration;
|
16 |
|
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
17 |
|
|
|
18 |
|
|
import com.mongodb.DB;
|
19 |
|
|
|
20 |
|
|
import eu.dnetlib.data.mdstore.MDStoreServiceException;
|
21 |
|
|
import eu.dnetlib.data.mdstore.modular.RecordParser;
|
22 |
|
|
import eu.dnetlib.data.mdstore.modular.connector.MDStoreDao;
|
23 |
|
|
import eu.dnetlib.data.mdstore.modular.connector.MDStoreTransactionManager;
|
24 |
|
|
|
25 |
|
|
@Ignore
|
26 |
|
|
@RunWith(SpringJUnit4ClassRunner.class)
|
27 |
|
|
@ContextConfiguration(classes = ConfigurationTestConfig.class)
|
28 |
|
|
public class FeedSpeedTest {
|
29 |
|
|
|
30 |
33870
|
andrea.man
|
private static final int N_RECORDS = 68271;
|
31 |
33806
|
andrea.man
|
|
32 |
|
|
@Autowired
|
33 |
|
|
private DB db;
|
34 |
|
|
|
35 |
|
|
@Autowired
|
36 |
|
|
private MDStoreTransactionManager manager;
|
37 |
|
|
|
38 |
|
|
@Autowired
|
39 |
|
|
private MDStoreDao dao;
|
40 |
|
|
|
41 |
|
|
@Autowired
|
42 |
|
|
private RecordParser recordParser;
|
43 |
|
|
|
44 |
|
|
@Ignore
|
45 |
33870
|
andrea.man
|
@Test
|
46 |
|
|
public void testSpeedFromFolder() throws IOException {
|
47 |
|
|
Iterable<String> iterable = new Iterable<String>() {
|
48 |
|
|
|
49 |
|
|
private int counter = 0;
|
50 |
|
|
private double last = System.currentTimeMillis();
|
51 |
|
|
|
52 |
|
|
@Override
|
53 |
|
|
public Iterator<String> iterator() {
|
54 |
|
|
return new Iterator<String>() {
|
55 |
|
|
|
56 |
|
|
@Override
|
57 |
|
|
public boolean hasNext() {
|
58 |
|
|
return counter < N_RECORDS;
|
59 |
|
|
}
|
60 |
|
|
|
61 |
|
|
@Override
|
62 |
|
|
public String next() {
|
63 |
|
|
if (counter % 10000 == 0) {
|
64 |
|
|
System.out.println("10K records processed in " + (System.currentTimeMillis() - last) / 1000 + " seconds");
|
65 |
|
|
last = System.currentTimeMillis();
|
66 |
|
|
}
|
67 |
|
|
|
68 |
|
|
File f = new File(String.format("/var/lib/eagle/content/EDH/HD%06d.xml", counter++));
|
69 |
|
|
if (f.exists()) {
|
70 |
|
|
try {
|
71 |
|
|
FileInputStream fileInputStream = new FileInputStream(f);
|
72 |
|
|
String s = IOUtils.toString(fileInputStream);
|
73 |
|
|
fileInputStream.close();
|
74 |
|
|
return s;
|
75 |
|
|
} catch (Exception e) {
|
76 |
|
|
return null;
|
77 |
|
|
}
|
78 |
|
|
} else {
|
79 |
|
|
try {
|
80 |
|
|
FileInputStream fileInputStream = new FileInputStream(new File("/var/lib/eagle/content/EDH/HD000001.xml"));
|
81 |
|
|
String s = IOUtils.toString(fileInputStream);
|
82 |
|
|
fileInputStream.close();
|
83 |
|
|
return s;
|
84 |
|
|
} catch (Exception e) {
|
85 |
|
|
return null;
|
86 |
|
|
}
|
87 |
|
|
}
|
88 |
|
|
}
|
89 |
|
|
|
90 |
|
|
@Override
|
91 |
|
|
public void remove() {}
|
92 |
|
|
};
|
93 |
|
|
}
|
94 |
|
|
};
|
95 |
|
|
|
96 |
|
|
MongoMDStore mdStore = new MongoMDStore(UUID.randomUUID().toString(), db.getCollection("speed_test"), recordParser, true);
|
97 |
|
|
mdStore.feed(iterable, false);
|
98 |
|
|
}
|
99 |
|
|
|
100 |
|
|
@Ignore
|
101 |
|
|
@Test
|
102 |
|
|
public void testFeedSpeedFromTemplate() throws MDStoreServiceException, IOException {
|
103 |
33806
|
andrea.man
|
MongoMDStore mdStore = new MongoMDStore(UUID.randomUUID().toString(), db.getCollection("speed_test"), recordParser, false);
|
104 |
|
|
mdStore.feed(new Iterable<String>() {
|
105 |
|
|
|
106 |
|
|
private int counter = 0;
|
107 |
|
|
private double last = System.currentTimeMillis();
|
108 |
34031
|
sandro.lab
|
private String templateRecord = IOUtils.toString(new ClassPathResource("/eu/dnetlib/data/mdstore/modular/mongodb/templateRecord.xml")
|
109 |
|
|
.getInputStream());
|
110 |
33806
|
andrea.man
|
|
111 |
|
|
@Override
|
112 |
|
|
public Iterator<String> iterator() {
|
113 |
|
|
return new Iterator<String>() {
|
114 |
|
|
|
115 |
|
|
@Override
|
116 |
|
|
public boolean hasNext() {
|
117 |
|
|
return counter < N_RECORDS;
|
118 |
|
|
}
|
119 |
|
|
|
120 |
|
|
@Override
|
121 |
|
|
public String next() {
|
122 |
|
|
if (counter % 10000 == 0) {
|
123 |
|
|
System.out.println("10K records processed in " + (System.currentTimeMillis() - last) / 1000 + " seconds");
|
124 |
|
|
last = System.currentTimeMillis();
|
125 |
|
|
}
|
126 |
33870
|
andrea.man
|
|
127 |
|
|
File f = new File(String.format("/var/lib/eagle/content/EDH/HD%06d.xml", counter++));
|
128 |
|
|
if (f.exists()) {
|
129 |
|
|
try {
|
130 |
|
|
FileInputStream fileInputStream = new FileInputStream(f);
|
131 |
|
|
String s = IOUtils.toString(fileInputStream);
|
132 |
|
|
fileInputStream.close();
|
133 |
|
|
return s;
|
134 |
|
|
} catch (Exception e) {
|
135 |
|
|
return null;
|
136 |
|
|
}
|
137 |
|
|
} else {
|
138 |
|
|
counter++;
|
139 |
|
|
try {
|
140 |
|
|
FileInputStream fileInputStream = new FileInputStream(new File("/var/lib/eagle/content/EDH/HD000009.xml"));
|
141 |
|
|
String s = IOUtils.toString(fileInputStream);
|
142 |
|
|
fileInputStream.close();
|
143 |
|
|
return s;
|
144 |
|
|
} catch (Exception e) {
|
145 |
|
|
return null;
|
146 |
|
|
}
|
147 |
|
|
}
|
148 |
33806
|
andrea.man
|
}
|
149 |
|
|
|
150 |
|
|
@Override
|
151 |
|
|
public void remove() {}
|
152 |
|
|
};
|
153 |
|
|
}
|
154 |
|
|
}, false);
|
155 |
|
|
}
|
156 |
|
|
}
|