use of co.rsk.db.importer.provider.index.data.BootstrapDataIndex in project rskj by rsksmart.
the class BootstrapIndexCandidateSelectorTest method getMaximumCommonHeightDataThreeEntries.
@Test
public void getMaximumCommonHeightDataThreeEntries() {
List<String> keys = Arrays.asList("key1", "key2");
BootstrapIndexCandidateSelector indexMCH = new BootstrapIndexCandidateSelector(keys, 2);
List<BootstrapDataIndex> indexes = new ArrayList<>();
ArrayList<BootstrapDataEntry> entries = new ArrayList<>();
ArrayList<BootstrapDataEntry> entries2 = new ArrayList<>();
entries.add(new BootstrapDataEntry(1, "", "dbPath", "hash", new BootstrapDataSignature("r", "s")));
entries.add(new BootstrapDataEntry(2, "", "dbPath", "hash", new BootstrapDataSignature("r", "s")));
entries2.add(new BootstrapDataEntry(1, "", "dbPath", "hash", new BootstrapDataSignature("r", "s")));
indexes.add(new BootstrapDataIndex(entries));
indexes.add(new BootstrapDataIndex(entries2));
BootstrapIndexCandidateSelector.HeightCandidate heightCandidate = indexMCH.getHeightData(indexes);
assertEquals(1, heightCandidate.getHeight());
}
use of co.rsk.db.importer.provider.index.data.BootstrapDataIndex in project rskj by rsksmart.
the class BootstrapIndexRetrieverTest method retrievePublicKey.
@Test
public void retrievePublicKey() throws IOException {
ObjectMapper objectMapper = mock(ObjectMapper.class);
BootstrapDataIndex bdi = new BootstrapDataIndex(Collections.singletonList(new BootstrapDataEntry(1, "", "db", "hash", new BootstrapDataSignature("r", "s"))));
when(objectMapper.readValue(any(URL.class), eq(BootstrapDataIndex.class))).thenReturn(bdi);
BootstrapURLProvider bootstrapUrlProvider = mock(BootstrapURLProvider.class);
when(bootstrapUrlProvider.getFullURL(any())).thenReturn(new URL("http://localhost"));
BootstrapIndexRetriever bootstrapIndexRetriever = new BootstrapIndexRetriever(Collections.singletonList("key1"), bootstrapUrlProvider, objectMapper);
List<BootstrapDataIndex> indices = bootstrapIndexRetriever.retrieve();
Assert.assertTrue(indices.contains(bdi));
}
use of co.rsk.db.importer.provider.index.data.BootstrapDataIndex in project rskj by rsksmart.
the class BootstrapIndexRetriever method retrieve.
public List<BootstrapDataIndex> retrieve() {
List<BootstrapDataIndex> indices = new ArrayList<>();
for (String pk : publicKeys) {
String indexSuffix = pk + "/" + INDEX_NAME;
URL indexURL = bootstrapUrlProvider.getFullURL(indexSuffix);
indices.add(readJson(indexURL));
}
return indices;
}
use of co.rsk.db.importer.provider.index.data.BootstrapDataIndex in project rskj by rsksmart.
the class BootstrapIndexCandidateSelector method getEntriesPerHeight.
private Map<Long, Map<String, BootstrapDataEntry>> getEntriesPerHeight(List<BootstrapDataIndex> indexes) {
// the outer map represents the tuples (height, heightEntries)
// the inner map represents the tuples (source, dbEntry)
Map<Long, Map<String, BootstrapDataEntry>> entriesPerHeight = new HashMap<>();
// each iteration is an index from a different source, each index contains many entries
for (int i = 0; i < indexes.size(); i++) {
BootstrapDataIndex bdi = indexes.get(i);
String publicKey = publicKeys.get(i);
// all the items for this index belongs to the same source
for (BootstrapDataEntry bde : bdi.getDbs()) {
Map<String, BootstrapDataEntry> entries = entriesPerHeight.computeIfAbsent(bde.getHeight(), k -> new HashMap<>());
// if any height is duplicated on a single file the process is stopped
if (entries.get(publicKey) != null) {
throw new BootstrapImportException(String.format("There is an invalid file from %s: it has 2 entries from same height %d", publicKey, bde.getHeight()));
}
entries.put(publicKey, bde);
}
}
if (entriesPerHeight.isEmpty()) {
throw new BootstrapImportException("Downloaded files contain no height entries");
}
return entriesPerHeight;
}
use of co.rsk.db.importer.provider.index.data.BootstrapDataIndex in project rskj by rsksmart.
the class BootstrapIndexCandidateSelectorTest method getMaximumCommonHeightDataDuplicatedEntries.
@Test(expected = BootstrapImportException.class)
public void getMaximumCommonHeightDataDuplicatedEntries() {
List<String> keys = Arrays.asList("key1", "key2");
BootstrapIndexCandidateSelector indexMCH = new BootstrapIndexCandidateSelector(keys, 2);
List<BootstrapDataIndex> indexes = new ArrayList<>();
ArrayList<BootstrapDataEntry> entries = new ArrayList<>();
entries.add(new BootstrapDataEntry(1, "", "dbPath", "hash", new BootstrapDataSignature("r", "s")));
entries.add(new BootstrapDataEntry(1, "", "dbPath", "hash", new BootstrapDataSignature("r", "s")));
indexes.add(new BootstrapDataIndex(entries));
indexMCH.getHeightData(indexes);
}
Aggregations