Search in sources :

Example 1 with BootstrapDataIndex

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());
}
Also used : BootstrapDataSignature(co.rsk.db.importer.provider.index.data.BootstrapDataSignature) BootstrapDataEntry(co.rsk.db.importer.provider.index.data.BootstrapDataEntry) ArrayList(java.util.ArrayList) BootstrapDataIndex(co.rsk.db.importer.provider.index.data.BootstrapDataIndex) Test(org.junit.Test)

Example 2 with BootstrapDataIndex

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));
}
Also used : BootstrapDataSignature(co.rsk.db.importer.provider.index.data.BootstrapDataSignature) BootstrapDataEntry(co.rsk.db.importer.provider.index.data.BootstrapDataEntry) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BootstrapDataIndex(co.rsk.db.importer.provider.index.data.BootstrapDataIndex) URL(java.net.URL) BootstrapURLProvider(co.rsk.db.importer.BootstrapURLProvider) Test(org.junit.Test)

Example 3 with BootstrapDataIndex

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;
}
Also used : ArrayList(java.util.ArrayList) BootstrapDataIndex(co.rsk.db.importer.provider.index.data.BootstrapDataIndex) URL(java.net.URL)

Example 4 with BootstrapDataIndex

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;
}
Also used : BootstrapDataEntry(co.rsk.db.importer.provider.index.data.BootstrapDataEntry) BootstrapImportException(co.rsk.db.importer.BootstrapImportException) BootstrapDataIndex(co.rsk.db.importer.provider.index.data.BootstrapDataIndex)

Example 5 with BootstrapDataIndex

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);
}
Also used : BootstrapDataSignature(co.rsk.db.importer.provider.index.data.BootstrapDataSignature) BootstrapDataEntry(co.rsk.db.importer.provider.index.data.BootstrapDataEntry) ArrayList(java.util.ArrayList) BootstrapDataIndex(co.rsk.db.importer.provider.index.data.BootstrapDataIndex) Test(org.junit.Test)

Aggregations

BootstrapDataIndex (co.rsk.db.importer.provider.index.data.BootstrapDataIndex)8 BootstrapDataEntry (co.rsk.db.importer.provider.index.data.BootstrapDataEntry)7 BootstrapDataSignature (co.rsk.db.importer.provider.index.data.BootstrapDataSignature)6 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 URL (java.net.URL)2 BootstrapImportException (co.rsk.db.importer.BootstrapImportException)1 BootstrapURLProvider (co.rsk.db.importer.BootstrapURLProvider)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1