Search in sources :

Example 1 with BootstrapIndexCandidateSelector

use of co.rsk.db.importer.provider.index.BootstrapIndexCandidateSelector in project rskj by rsksmart.

the class BootstrapDataProviderTest method retrieveData.

@Test
public void retrieveData() {
    BootstrapDataVerifier bootstrapDataVerifier = mock(BootstrapDataVerifier.class);
    when(bootstrapDataVerifier.verifyEntries(any())).thenReturn(2);
    BootstrapFileHandler bootstrapFileHandler = mock(BootstrapFileHandler.class);
    BootstrapIndexCandidateSelector bootstrapIndexCandidateSelector = mock(BootstrapIndexCandidateSelector.class);
    Map<String, BootstrapDataEntry> entries = new HashMap<>();
    BootstrapIndexCandidateSelector.HeightCandidate mchd = new BootstrapIndexCandidateSelector.HeightCandidate(1L, entries);
    when(bootstrapIndexCandidateSelector.getHeightData(any())).thenReturn(mchd);
    BootstrapDataProvider bootstrapDataProvider = new BootstrapDataProvider(bootstrapDataVerifier, bootstrapFileHandler, bootstrapIndexCandidateSelector, mock(BootstrapIndexRetriever.class), 2);
    bootstrapDataProvider.retrieveData();
}
Also used : BootstrapIndexRetriever(co.rsk.db.importer.provider.index.BootstrapIndexRetriever) HashMap(java.util.HashMap) BootstrapDataEntry(co.rsk.db.importer.provider.index.data.BootstrapDataEntry) BootstrapIndexCandidateSelector(co.rsk.db.importer.provider.index.BootstrapIndexCandidateSelector) Test(org.junit.Test)

Example 2 with BootstrapIndexCandidateSelector

use of co.rsk.db.importer.provider.index.BootstrapIndexCandidateSelector in project rskj by rsksmart.

the class BootstrapDataProviderTest method retrieveDataInsufficientsSources.

@Test(expected = BootstrapImportException.class)
public void retrieveDataInsufficientsSources() {
    BootstrapDataVerifier bootstrapDataVerifier = mock(BootstrapDataVerifier.class);
    when(bootstrapDataVerifier.verifyEntries(any())).thenReturn(1);
    BootstrapFileHandler bootstrapFileHandler = mock(BootstrapFileHandler.class);
    BootstrapIndexCandidateSelector bootstrapIndexCandidateSelector = mock(BootstrapIndexCandidateSelector.class);
    Map<String, BootstrapDataEntry> entries = new HashMap<>();
    BootstrapIndexCandidateSelector.HeightCandidate mchd = new BootstrapIndexCandidateSelector.HeightCandidate(1L, entries);
    when(bootstrapIndexCandidateSelector.getHeightData(any())).thenReturn(mchd);
    BootstrapDataProvider bootstrapDataProvider = new BootstrapDataProvider(bootstrapDataVerifier, bootstrapFileHandler, bootstrapIndexCandidateSelector, mock(BootstrapIndexRetriever.class), 2);
    bootstrapDataProvider.retrieveData();
}
Also used : BootstrapIndexRetriever(co.rsk.db.importer.provider.index.BootstrapIndexRetriever) HashMap(java.util.HashMap) BootstrapDataEntry(co.rsk.db.importer.provider.index.data.BootstrapDataEntry) BootstrapIndexCandidateSelector(co.rsk.db.importer.provider.index.BootstrapIndexCandidateSelector) Test(org.junit.Test)

Example 3 with BootstrapIndexCandidateSelector

use of co.rsk.db.importer.provider.index.BootstrapIndexCandidateSelector in project rskj by rsksmart.

the class RskContext method getBootstrapImporter.

public synchronized BootstrapImporter getBootstrapImporter() {
    checkIfNotClosed();
    if (bootstrapImporter == null) {
        RskSystemProperties systemProperties = getRskSystemProperties();
        List<String> publicKeys = systemProperties.importTrustedKeys();
        int minimumRequired = publicKeys.size() / 2 + 1;
        if (minimumRequired < 2) {
            logger.warn("Configuration has less trusted sources than the minimum required {} of 2", minimumRequired);
            minimumRequired = 2;
        }
        BootstrapURLProvider bootstrapUrlProvider = new BootstrapURLProvider(systemProperties.importUrl());
        bootstrapImporter = new BootstrapImporter(getBlockStore(), getTrieStore(), blockFactory, new BootstrapDataProvider(new BootstrapDataVerifier(), new BootstrapFileHandler(bootstrapUrlProvider, new Unzipper()), new BootstrapIndexCandidateSelector(publicKeys, minimumRequired), new BootstrapIndexRetriever(publicKeys, bootstrapUrlProvider, new ObjectMapper()), minimumRequired));
    }
    return bootstrapImporter;
}
Also used : BootstrapFileHandler(co.rsk.db.importer.provider.BootstrapFileHandler) Unzipper(co.rsk.db.importer.provider.Unzipper) BootstrapIndexCandidateSelector(co.rsk.db.importer.provider.index.BootstrapIndexCandidateSelector) BootstrapImporter(co.rsk.db.importer.BootstrapImporter) BootstrapDataProvider(co.rsk.db.importer.provider.BootstrapDataProvider) BootstrapIndexRetriever(co.rsk.db.importer.provider.index.BootstrapIndexRetriever) BootstrapDataVerifier(co.rsk.db.importer.provider.BootstrapDataVerifier) BootstrapURLProvider(co.rsk.db.importer.BootstrapURLProvider) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

BootstrapIndexCandidateSelector (co.rsk.db.importer.provider.index.BootstrapIndexCandidateSelector)3 BootstrapIndexRetriever (co.rsk.db.importer.provider.index.BootstrapIndexRetriever)3 BootstrapDataEntry (co.rsk.db.importer.provider.index.data.BootstrapDataEntry)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 BootstrapImporter (co.rsk.db.importer.BootstrapImporter)1 BootstrapURLProvider (co.rsk.db.importer.BootstrapURLProvider)1 BootstrapDataProvider (co.rsk.db.importer.provider.BootstrapDataProvider)1 BootstrapDataVerifier (co.rsk.db.importer.provider.BootstrapDataVerifier)1 BootstrapFileHandler (co.rsk.db.importer.provider.BootstrapFileHandler)1 Unzipper (co.rsk.db.importer.provider.Unzipper)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1