Search in sources :

Example 26 with Range

use of org.apache.commons.lang3.Range in project cassandra by apache.

the class RangeStreamer method calculateRangesToFetchWithPreferredEndpoints.

/**
 * Get a map of all ranges and the source that will be cleaned up once this bootstrapped node is added for the given ranges.
 * For each range, the list should only contain a single source. This allows us to consistently migrate data without violating
 * consistency.
 */
public static EndpointsByReplica calculateRangesToFetchWithPreferredEndpoints(BiFunction<InetAddressAndPort, EndpointsForRange, EndpointsForRange> snitchGetSortedListByProximity, AbstractReplicationStrategy strat, ReplicaCollection<?> fetchRanges, boolean useStrictConsistency, TokenMetadata tmdBefore, TokenMetadata tmdAfter, String keyspace, Collection<SourceFilter> sourceFilters) {
    EndpointsByRange rangeAddresses = strat.getRangeAddresses(tmdBefore);
    InetAddressAndPort localAddress = FBUtilities.getBroadcastAddressAndPort();
    logger.debug("Keyspace: {}", keyspace);
    logger.debug("To fetch RN: {}", fetchRanges);
    logger.debug("Fetch ranges: {}", rangeAddresses);
    Predicate<Replica> testSourceFilters = and(sourceFilters);
    Function<EndpointsForRange, EndpointsForRange> sorted = endpoints -> snitchGetSortedListByProximity.apply(localAddress, endpoints);
    // This list of replicas is just candidates. With strict consistency it's going to be a narrow list.
    EndpointsByReplica.Builder rangesToFetchWithPreferredEndpoints = new EndpointsByReplica.Builder();
    for (Replica toFetch : fetchRanges) {
        // Replica that is sufficient to provide the data we need
        // With strict consistency and transient replication we may end up with multiple types
        // so this isn't used with strict consistency
        Predicate<Replica> isSufficient = r -> toFetch.isTransient() || r.isFull();
        logger.debug("To fetch {}", toFetch);
        for (Range<Token> range : rangeAddresses.keySet()) {
            if (!range.contains(toFetch.range()))
                continue;
            final EndpointsForRange oldEndpoints = sorted.apply(rangeAddresses.get(range));
            // Ultimately we populate this with whatever is going to be fetched from to satisfy toFetch
            // It could be multiple endpoints and we must fetch from all of them if they are there
            // With transient replication and strict consistency this is to get the full data from a full replica and
            // transient data from the transient replica losing data
            EndpointsForRange sources;
            // Due to CASSANDRA-5953 we can have a higher RF than we have endpoints.
            // So we need to be careful to only be strict when endpoints == RF
            boolean isStrictConsistencyApplicable = useStrictConsistency && (oldEndpoints.size() == strat.getReplicationFactor().allReplicas);
            if (isStrictConsistencyApplicable) {
                EndpointsForRange strictEndpoints;
                // Start with two sets of who replicates the range before and who replicates it after
                EndpointsForRange newEndpoints = strat.calculateNaturalReplicas(toFetch.range().right, tmdAfter);
                logger.debug("Old endpoints {}", oldEndpoints);
                logger.debug("New endpoints {}", newEndpoints);
                // Remove new endpoints from old endpoints based on address
                strictEndpoints = oldEndpoints.without(newEndpoints.endpoints());
                if (strictEndpoints.size() > 1)
                    throw new AssertionError("Expected <= 1 endpoint but found " + strictEndpoints);
                // required for strict consistency
                if (!all(strictEndpoints, testSourceFilters))
                    throw new IllegalStateException("Necessary replicas for strict consistency were removed by source filters: " + buildErrorMessage(sourceFilters, strictEndpoints));
                // So it's an error if we don't find what we need.
                if (strictEndpoints.isEmpty() && toFetch.isTransient())
                    throw new AssertionError("If there are no endpoints to fetch from then we must be transitioning from transient to full for range " + toFetch);
                if (!any(strictEndpoints, isSufficient)) {
                    // need an additional replica; include all our filters, to ensure we include a matching node
                    Optional<Replica> fullReplica = Iterables.<Replica>tryFind(oldEndpoints, and(isSufficient, testSourceFilters)).toJavaUtil();
                    if (fullReplica.isPresent())
                        strictEndpoints = Endpoints.concat(strictEndpoints, EndpointsForRange.of(fullReplica.get()));
                    else
                        throw new IllegalStateException("Couldn't find any matching sufficient replica out of " + buildErrorMessage(sourceFilters, oldEndpoints));
                }
                sources = strictEndpoints;
            } else {
                // Without strict consistency we have given up on correctness so no point in fetching from
                // a random full + transient replica since it's also likely to lose data
                // Also apply testSourceFilters that were given to us so we can safely select a single source
                sources = sorted.apply(oldEndpoints.filter(and(isSufficient, testSourceFilters)));
                // Limit it to just the first possible source, we don't need more than one and downstream
                // will fetch from every source we supply
                sources = sources.size() > 0 ? sources.subList(0, 1) : sources;
            }
            // storing range and preferred endpoint set
            rangesToFetchWithPreferredEndpoints.putAll(toFetch, sources, Conflict.NONE);
            logger.debug("Endpoints to fetch for {} are {}", toFetch, sources);
        }
        EndpointsForRange addressList = rangesToFetchWithPreferredEndpoints.getIfPresent(toFetch);
        if (addressList == null)
            throw new IllegalStateException("Failed to find endpoints to fetch " + toFetch);
        /*
              * When we move forwards (shrink our bucket) we are the one losing a range and no one else loses
              * from that action (we also don't gain). When we move backwards there are two people losing a range. One is a full replica
              * and the other is a transient replica. So we must need fetch from two places in that case for the full range we gain.
              * For a transient range we only need to fetch from one.
              */
        if (useStrictConsistency && addressList.size() > 1 && (addressList.filter(Replica::isFull).size() > 1 || addressList.filter(Replica::isTransient).size() > 1))
            throw new IllegalStateException(String.format("Multiple strict sources found for %s, sources: %s", toFetch, addressList));
        // We must have enough stuff to fetch from
        if (!any(addressList, isSufficient)) {
            if (strat.getReplicationFactor().allReplicas == 1) {
                if (useStrictConsistency) {
                    logger.warn("A node required to move the data consistently is down");
                    throw new IllegalStateException("Unable to find sufficient sources for streaming range " + toFetch + " in keyspace " + keyspace + " with RF=1. " + "Ensure this keyspace contains replicas in the source datacenter.");
                } else
                    logger.warn("Unable to find sufficient sources for streaming range {} in keyspace {} with RF=1. " + "Keyspace might be missing data.", toFetch, keyspace);
            } else {
                if (useStrictConsistency)
                    logger.warn("A node required to move the data consistently is down");
                throw new IllegalStateException("Unable to find sufficient sources for streaming range " + toFetch + " in keyspace " + keyspace);
            }
        }
    }
    return rangesToFetchWithPreferredEndpoints.build();
}
Also used : BiFunction(java.util.function.BiFunction) LoggerFactory(org.slf4j.LoggerFactory) Iterables.all(com.google.common.collect.Iterables.all) StringUtils(org.apache.commons.lang3.StringUtils) Gossiper(org.apache.cassandra.gms.Gossiper) NetworkTopologyStrategy(org.apache.cassandra.locator.NetworkTopologyStrategy) Predicates.and(com.google.common.base.Predicates.and) StreamResultFuture(org.apache.cassandra.streaming.StreamResultFuture) Replica.fullReplica(org.apache.cassandra.locator.Replica.fullReplica) HashMultimap(com.google.common.collect.HashMultimap) Replicas(org.apache.cassandra.locator.Replicas) Endpoints(org.apache.cassandra.locator.Endpoints) Predicates.not(com.google.common.base.Predicates.not) ReplicaCollection(org.apache.cassandra.locator.ReplicaCollection) Map(java.util.Map) EndpointsByRange(org.apache.cassandra.locator.EndpointsByRange) Keyspace(org.apache.cassandra.db.Keyspace) EndpointsForRange(org.apache.cassandra.locator.EndpointsForRange) FBUtilities(org.apache.cassandra.utils.FBUtilities) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) RangesAtEndpoint(org.apache.cassandra.locator.RangesAtEndpoint) List(java.util.List) Predicate(com.google.common.base.Predicate) Conflict(org.apache.cassandra.locator.ReplicaCollection.Builder.Conflict) Optional(java.util.Optional) FailureDetector(org.apache.cassandra.gms.FailureDetector) Iterables.any(com.google.common.collect.Iterables.any) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) Iterables(com.google.common.collect.Iterables) HashMap(java.util.HashMap) Multimap(com.google.common.collect.Multimap) Function(java.util.function.Function) SystemKeyspace(org.apache.cassandra.db.SystemKeyspace) ArrayList(java.util.ArrayList) IEndpointSnitch(org.apache.cassandra.locator.IEndpointSnitch) TokenMetadata(org.apache.cassandra.locator.TokenMetadata) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) StreamOperation(org.apache.cassandra.streaming.StreamOperation) Logger(org.slf4j.Logger) Replica(org.apache.cassandra.locator.Replica) IFailureDetector(org.apache.cassandra.gms.IFailureDetector) PreviewKind(org.apache.cassandra.streaming.PreviewKind) AbstractReplicationStrategy(org.apache.cassandra.locator.AbstractReplicationStrategy) StreamPlan(org.apache.cassandra.streaming.StreamPlan) EndpointsByReplica(org.apache.cassandra.locator.EndpointsByReplica) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) LocalStrategy(org.apache.cassandra.locator.LocalStrategy) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) EndpointsByRange(org.apache.cassandra.locator.EndpointsByRange) Replica.fullReplica(org.apache.cassandra.locator.Replica.fullReplica) Replica(org.apache.cassandra.locator.Replica) EndpointsByReplica(org.apache.cassandra.locator.EndpointsByReplica) EndpointsByReplica(org.apache.cassandra.locator.EndpointsByReplica) EndpointsForRange(org.apache.cassandra.locator.EndpointsForRange)

Example 27 with Range

use of org.apache.commons.lang3.Range in project neo4j by neo4j.

the class KeySearchTest method shouldSearchAndFindOnRandomData.

@Test
void shouldSearchAndFindOnRandomData() throws IOException {
    // GIVEN a leaf node with random, although sorted (as of course it must be to binary-search), data
    node.initializeLeaf(cursor, STABLE_GENERATION, UNSTABLE_GENERATION);
    List<MutableLong> keys = new ArrayList<>();
    int currentKey = random.nextInt(10_000);
    MutableLong key = layout.newKey();
    int keyCount = 0;
    while (true) {
        MutableLong expectedKey = layout.newKey();
        key.setValue(currentKey);
        if (node.leafOverflow(cursor, keyCount, key, dummyValue) != NO) {
            break;
        }
        layout.copyKey(key, expectedKey);
        keys.add(keyCount, expectedKey);
        node.insertKeyValueAt(cursor, key, dummyValue, keyCount, keyCount, STABLE_GENERATION, UNSTABLE_GENERATION, NULL);
        currentKey += random.nextInt(100) + 10;
        keyCount++;
    }
    TreeNode.setKeyCount(cursor, keyCount);
    // WHEN searching for random keys within that general range
    MutableLong searchKey = layout.newKey();
    for (int i = 0; i < 1_000; i++) {
        searchKey.setValue(random.nextInt(currentKey + 10));
        int searchResult = search(cursor, node, LEAF, searchKey, readKey, keyCount, NULL);
        // THEN position should be as expected
        boolean exists = contains(keys, searchKey, layout);
        int position = KeySearch.positionOf(searchResult);
        assertEquals(exists, KeySearch.isHit(searchResult));
        if (layout.compare(searchKey, keys.get(0)) <= 0) {
            // Our search key was lower than any of our keys, expect 0
            assertEquals(0, position);
        } else {
            // step backwards through our expected keys and see where it should fit, assert that fact
            boolean found = false;
            for (int j = keyCount - 1; j >= 0; j--) {
                if (layout.compare(searchKey, keys.get(j)) > 0) {
                    assertEquals(j + 1, position);
                    found = true;
                    break;
                }
            }
            assertTrue(found);
        }
    }
}
Also used : MutableLong(org.apache.commons.lang3.mutable.MutableLong) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 28 with Range

use of org.apache.commons.lang3.Range in project gerrit by GerritCodeReview.

the class HttpPluginServlet method sendAutoIndex.

private void sendAutoIndex(PluginContentScanner scanner, final String prefix, final String pluginName, PluginResourceKey cacheKey, HttpServletResponse res, long lastModifiedTime) throws IOException {
    List<PluginEntry> cmds = new ArrayList<>();
    List<PluginEntry> servlets = new ArrayList<>();
    List<PluginEntry> restApis = new ArrayList<>();
    List<PluginEntry> docs = new ArrayList<>();
    PluginEntry about = null;
    PluginEntry toc = null;
    Predicate<PluginEntry> filter = entry -> {
        String name = entry.getName();
        Optional<Long> size = entry.getSize();
        if (name.startsWith(prefix) && (name.endsWith(".md") || name.endsWith(".html")) && size.isPresent()) {
            if (size.get() <= 0 || size.get() > SMALL_RESOURCE) {
                logger.atWarning().log("Plugin %s: %s omitted from document index. " + "Size %d out of range (0,%d).", pluginName, name.substring(prefix.length()), size.get(), SMALL_RESOURCE);
                return false;
            }
            return true;
        }
        return false;
    };
    List<PluginEntry> entries = scanner.entries().filter(filter).collect(toList());
    for (PluginEntry entry : entries) {
        String name = entry.getName().substring(prefix.length());
        if (name.startsWith("cmd-")) {
            cmds.add(entry);
        } else if (name.startsWith("servlet-")) {
            servlets.add(entry);
        } else if (name.startsWith("rest-api-")) {
            restApis.add(entry);
        } else if (name.startsWith("about.")) {
            if (about == null) {
                about = entry;
            } else {
                logger.atWarning().log("Plugin %s: Multiple 'about' documents found; using %s", pluginName, about.getName().substring(prefix.length()));
            }
        } else if (name.startsWith("toc.")) {
            if (toc == null) {
                toc = entry;
            } else {
                logger.atWarning().log("Plugin %s: Multiple 'toc' documents found; using %s", pluginName, toc.getName().substring(prefix.length()));
            }
        } else {
            docs.add(entry);
        }
    }
    cmds.sort(PluginEntry.COMPARATOR_BY_NAME);
    docs.sort(PluginEntry.COMPARATOR_BY_NAME);
    StringBuilder md = new StringBuilder();
    md.append(String.format("# Plugin %s #\n", pluginName));
    md.append("\n");
    appendPluginInfoTable(md, scanner.getManifest().getMainAttributes());
    if (about != null) {
        appendPageAsSection(scanner, about, "About", md);
    }
    if (toc != null) {
        appendPageAsSection(scanner, toc, "Documentaion", md);
    } else {
        appendEntriesSection(scanner, docs, "Documentation", md, prefix, 0);
        appendEntriesSection(scanner, servlets, "Servlets", md, prefix, "servlet-".length());
        appendEntriesSection(scanner, restApis, "REST APIs", md, prefix, "rest-api-".length());
        appendEntriesSection(scanner, cmds, "Commands", md, prefix, "cmd-".length());
    }
    sendMarkdownAsHtml(md.toString(), pluginName, cacheKey, res, lastModifiedTime);
}
Also used : RestApiServlet(com.google.gerrit.httpd.restapi.RestApiServlet) FileUtil.lastModified(com.google.gerrit.common.FileUtil.lastModified) FilterChain(javax.servlet.FilterChain) ResourceKey(com.google.gerrit.httpd.resources.ResourceKey) ACCESS_CONTROL_ALLOW_METHODS(com.google.common.net.HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS) ServletException(javax.servlet.ServletException) Inject(com.google.inject.Inject) StringUtils(org.apache.commons.lang3.StringUtils) PluginsCollection(com.google.gerrit.server.plugins.PluginsCollection) Config(org.eclipse.jgit.lib.Config) ACCESS_CONTROL_ALLOW_ORIGIN(com.google.common.net.HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN) SshInfo(com.google.gerrit.server.ssh.SshInfo) Matcher(java.util.regex.Matcher) HttpHeaders(com.google.common.net.HttpHeaders) Locale(java.util.Locale) Map(java.util.Map) Splitter(com.google.common.base.Splitter) StartPluginListener(com.google.gerrit.server.plugins.StartPluginListener) Path(java.nio.file.Path) ORIGIN(com.google.common.net.HttpHeaders.ORIGIN) ServletConfig(javax.servlet.ServletConfig) GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) HttpServlet(javax.servlet.http.HttpServlet) Predicate(java.util.function.Predicate) ApiType(com.google.gerrit.server.plugins.Plugin.ApiType) RawParseUtils(org.eclipse.jgit.util.RawParseUtils) MarkdownFormatter(com.google.gerrit.server.documentation.MarkdownFormatter) GuiceFilter(com.google.inject.servlet.GuiceFilter) Attributes(java.util.jar.Attributes) Resource(com.google.gerrit.httpd.resources.Resource) List(java.util.List) ReloadPluginListener(com.google.gerrit.server.plugins.ReloadPluginListener) ByteStreams(com.google.common.io.ByteStreams) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) UnsupportedEncodingException(java.io.UnsupportedEncodingException) FluentLogger(com.google.common.flogger.FluentLogger) ACCESS_CONTROL_ALLOW_CREDENTIALS(com.google.common.net.HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS) Joiner(com.google.common.base.Joiner) Singleton(com.google.inject.Singleton) PluginContentScanner(com.google.gerrit.server.plugins.PluginContentScanner) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) Strings(com.google.common.base.Strings) CanonicalWebUrl(com.google.gerrit.server.config.CanonicalWebUrl) HttpServletRequest(javax.servlet.http.HttpServletRequest) VARY(com.google.common.net.HttpHeaders.VARY) Lists(com.google.common.collect.Lists) Charset(java.nio.charset.Charset) Plugin(com.google.gerrit.server.plugins.Plugin) CacheHeaders(com.google.gerrit.util.http.CacheHeaders) ATTR_CHARACTER_ENCODING(com.google.gerrit.server.plugins.PluginEntry.ATTR_CHARACTER_ENCODING) OutputStream(java.io.OutputStream) RequestUtil(com.google.gerrit.util.http.RequestUtil) IO(org.eclipse.jgit.util.IO) Files(java.nio.file.Files) UTF_8(java.nio.charset.StandardCharsets.UTF_8) CharMatcher(com.google.common.base.CharMatcher) SmallResource(com.google.gerrit.httpd.resources.SmallResource) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) ATTR_CONTENT_TYPE(com.google.gerrit.server.plugins.PluginEntry.ATTR_CONTENT_TYPE) Maps(com.google.common.collect.Maps) InputStreamReader(java.io.InputStreamReader) PluginEntry(com.google.gerrit.server.plugins.PluginEntry) Collectors.toList(java.util.stream.Collectors.toList) Provider(com.google.inject.Provider) Named(com.google.inject.name.Named) ServletContext(javax.servlet.ServletContext) BufferedReader(java.io.BufferedReader) Cache(com.google.common.cache.Cache) MimeUtilFileTypeRegistry(com.google.gerrit.server.mime.MimeUtilFileTypeRegistry) InputStream(java.io.InputStream) Optional(java.util.Optional) ArrayList(java.util.ArrayList) PluginEntry(com.google.gerrit.server.plugins.PluginEntry)

Example 29 with Range

use of org.apache.commons.lang3.Range in project hbase by apache.

the class BackupAdminImpl method checkIfValidForMerge.

/**
 * Verifies that backup images are valid for merge.
 *
 * <ul>
 * <li>All backups MUST be in the same destination
 * <li>No FULL backups are allowed - only INCREMENTAL
 * <li>All backups must be in COMPLETE state
 * <li>No holes in backup list are allowed
 * </ul>
 * <p>
 * @param backupIds list of backup ids
 * @param table backup system table
 * @throws IOException if the backup image is not valid for merge
 */
private void checkIfValidForMerge(String[] backupIds, BackupSystemTable table) throws IOException {
    String backupRoot = null;
    final Set<TableName> allTables = new HashSet<>();
    final Set<String> allBackups = new HashSet<>();
    long minTime = Long.MAX_VALUE, maxTime = Long.MIN_VALUE;
    for (String backupId : backupIds) {
        BackupInfo bInfo = table.readBackupInfo(backupId);
        if (bInfo == null) {
            String msg = "Backup session " + backupId + " not found";
            throw new IOException(msg);
        }
        if (backupRoot == null) {
            backupRoot = bInfo.getBackupRootDir();
        } else if (!bInfo.getBackupRootDir().equals(backupRoot)) {
            throw new IOException("Found different backup destinations in a list of a backup sessions " + "\n1. " + backupRoot + "\n" + "2. " + bInfo.getBackupRootDir());
        }
        if (bInfo.getType() == BackupType.FULL) {
            throw new IOException("FULL backup image can not be merged for: \n" + bInfo);
        }
        if (bInfo.getState() != BackupState.COMPLETE) {
            throw new IOException("Backup image " + backupId + " can not be merged becuase of its state: " + bInfo.getState());
        }
        allBackups.add(backupId);
        allTables.addAll(bInfo.getTableNames());
        long time = bInfo.getStartTs();
        if (time < minTime) {
            minTime = time;
        }
        if (time > maxTime) {
            maxTime = time;
        }
    }
    final long startRangeTime = minTime;
    final long endRangeTime = maxTime;
    final String backupDest = backupRoot;
    // Check we have no 'holes' in backup id list
    // Filter 1 : backupRoot
    // Filter 2 : time range filter
    // Filter 3 : table filter
    BackupInfo.Filter destinationFilter = info -> info.getBackupRootDir().equals(backupDest);
    BackupInfo.Filter timeRangeFilter = info -> {
        long time = info.getStartTs();
        return time >= startRangeTime && time <= endRangeTime;
    };
    BackupInfo.Filter tableFilter = info -> {
        List<TableName> tables = info.getTableNames();
        return !Collections.disjoint(allTables, tables);
    };
    BackupInfo.Filter typeFilter = info -> info.getType() == BackupType.INCREMENTAL;
    BackupInfo.Filter stateFilter = info -> info.getState() == BackupState.COMPLETE;
    List<BackupInfo> allInfos = table.getBackupHistory(-1, destinationFilter, timeRangeFilter, tableFilter, typeFilter, stateFilter);
    if (allInfos.size() != allBackups.size()) {
        // Yes we have at least one  hole in backup image sequence
        List<String> missingIds = new ArrayList<>();
        for (BackupInfo info : allInfos) {
            if (allBackups.contains(info.getBackupId())) {
                continue;
            }
            missingIds.add(info.getBackupId());
        }
        String errMsg = "Sequence of backup ids has 'holes'. The following backup images must be added:" + org.apache.hadoop.util.StringUtils.join(",", missingIds);
        throw new IOException(errMsg);
    }
}
Also used : BackupRequest(org.apache.hadoop.hbase.backup.BackupRequest) FileSystem(org.apache.hadoop.fs.FileSystem) LoggerFactory(org.slf4j.LoggerFactory) BackupState(org.apache.hadoop.hbase.backup.BackupInfo.BackupState) BackupMergeJob(org.apache.hadoop.hbase.backup.BackupMergeJob) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) BackupInfo(org.apache.hadoop.hbase.backup.BackupInfo) BackupUtils(org.apache.hadoop.hbase.backup.util.BackupUtils) Map(java.util.Map) Configuration(org.apache.hadoop.conf.Configuration) Path(org.apache.hadoop.fs.Path) TableName(org.apache.hadoop.hbase.TableName) Logger(org.slf4j.Logger) BackupRestoreFactory(org.apache.hadoop.hbase.backup.BackupRestoreFactory) Set(java.util.Set) IOException(java.io.IOException) BackupRestoreConstants(org.apache.hadoop.hbase.backup.BackupRestoreConstants) BackupType(org.apache.hadoop.hbase.backup.BackupType) BackupSet(org.apache.hadoop.hbase.backup.util.BackupSet) HBackupFileSystem(org.apache.hadoop.hbase.backup.HBackupFileSystem) Lists(org.apache.hbase.thirdparty.com.google.common.collect.Lists) BackupClientFactory(org.apache.hadoop.hbase.backup.BackupClientFactory) RestoreRequest(org.apache.hadoop.hbase.backup.RestoreRequest) List(java.util.List) InterfaceAudience(org.apache.yetus.audience.InterfaceAudience) BackupAdmin(org.apache.hadoop.hbase.backup.BackupAdmin) Admin(org.apache.hadoop.hbase.client.Admin) Connection(org.apache.hadoop.hbase.client.Connection) EnvironmentEdgeManager(org.apache.hadoop.hbase.util.EnvironmentEdgeManager) Collections(java.util.Collections) ArrayList(java.util.ArrayList) IOException(java.io.IOException) BackupInfo(org.apache.hadoop.hbase.backup.BackupInfo) TableName(org.apache.hadoop.hbase.TableName) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet)

Example 30 with Range

use of org.apache.commons.lang3.Range in project Asqatasun by Asqatasun.

the class Rgaa40Rule110204Test method setProcess.

@Override
protected void setProcess() {
    // ----------------------------------------------------------------------
    // ------------------------------3NMI-01---------------------------------
    // ----------------------------------------------------------------------
    ProcessResult processResult = processPageTest("Rgaa40.Test.11.2.4-3NMI-01");
    checkResultIsPreQualified(processResult, 2, 2);
    checkRemarkIsPresent(processResult, TestSolution.NEED_MORE_INFO, RemarkMessageStore.MANUAL_CHECK_ON_ELEMENTS_MSG, HtmlElementStore.INPUT_ELEMENT, 1, new ImmutablePair(ARIA_LABELLEDBY_ATTR, "aria-labelledby-for-input-without-type-attribute"));
    checkRemarkIsPresent(processResult, TestSolution.NEED_MORE_INFO, RemarkMessageStore.MANUAL_CHECK_ON_ELEMENTS_MSG, HtmlElementStore.INPUT_ELEMENT, 2, new ImmutablePair(ARIA_LABELLEDBY_ATTR, "aria-labelledby-for-input-with-type-equal-to-text"));
    // ----------------------------------------------------------------------
    // ------------------------------3NMI-02---------------------------------
    // ----------------------------------------------------------------------
    processResult = processPageTest("Rgaa40.Test.11.2.4-3NMI-02");
    checkResultIsPreQualified(processResult, 17, 17);
    HashMap<Integer, String> mapTypeAttribute = new HashMap<Integer, String>();
    mapTypeAttribute.put(1, "checkbox");
    mapTypeAttribute.put(2, "color");
    mapTypeAttribute.put(3, "date");
    mapTypeAttribute.put(4, "datetime-local");
    mapTypeAttribute.put(5, "email");
    mapTypeAttribute.put(6, "file");
    mapTypeAttribute.put(7, "month");
    mapTypeAttribute.put(8, "number");
    mapTypeAttribute.put(9, "password");
    mapTypeAttribute.put(10, "radio");
    mapTypeAttribute.put(11, "range");
    mapTypeAttribute.put(12, "search");
    mapTypeAttribute.put(13, "tel");
    mapTypeAttribute.put(14, "text");
    mapTypeAttribute.put(15, "time");
    mapTypeAttribute.put(16, "url");
    mapTypeAttribute.put(17, "week");
    for (Map.Entry item : mapTypeAttribute.entrySet()) {
        int position = ((int) item.getKey());
        checkRemarkIsPresent(processResult, TestSolution.NEED_MORE_INFO, RemarkMessageStore.MANUAL_CHECK_ON_ELEMENTS_MSG, HtmlElementStore.INPUT_ELEMENT, position, new ImmutablePair(ARIA_LABELLEDBY_ATTR, "aria-labelledby-for-input-with-type-equal-to-" + item.getValue()));
    }
    // ----------------------------------------------------------------------
    // ------------------------------3NMI-03---------------------------------
    // ----------------------------------------------------------------------
    processResult = processPageTest("Rgaa40.Test.11.2.4-3NMI-03");
    checkResultIsPreQualified(processResult, 1, 1);
    checkRemarkIsPresent(processResult, TestSolution.NEED_MORE_INFO, RemarkMessageStore.MANUAL_CHECK_ON_ELEMENTS_MSG, HtmlElementStore.TEXTAREA_ELEMENT, 1, new ImmutablePair(ARIA_LABELLEDBY_ATTR, "aria-labelledby-id-for-TEXTAREA"));
    // ----------------------------------------------------------------------
    // ------------------------------3NMI-04---------------------------------
    // ----------------------------------------------------------------------
    processResult = processPageTest("Rgaa40.Test.11.2.4-3NMI-04");
    checkResultIsPreQualified(processResult, 3, 3);
    checkRemarkIsPresent(processResult, TestSolution.NEED_MORE_INFO, RemarkMessageStore.MANUAL_CHECK_ON_ELEMENTS_MSG, HtmlElementStore.SELECT_ELEMENT, 1, new ImmutablePair(ARIA_LABELLEDBY_ATTR, "aria-labelledby-id-for-SELECT"));
    checkRemarkIsPresent(processResult, TestSolution.NEED_MORE_INFO, RemarkMessageStore.MANUAL_CHECK_ON_ELEMENTS_MSG, HtmlElementStore.OPTGROUP_ELEMENT, 2, new ImmutablePair(ARIA_LABELLEDBY_ATTR, "aria-labelledby-id-for-OPTGROUP"));
    checkRemarkIsPresent(processResult, TestSolution.NEED_MORE_INFO, RemarkMessageStore.MANUAL_CHECK_ON_ELEMENTS_MSG, HtmlElementStore.OPTION_ELEMENT, 3, new ImmutablePair(ARIA_LABELLEDBY_ATTR, "aria-labelledby-id-for-OPTION"));
    // ----------------------------------------------------------------------
    // ------------------------------3NMI-05---------------------------------
    // ----------------------------------------------------------------------
    processResult = processPageTest("Rgaa40.Test.11.2.4-3NMI-05");
    checkResultIsPreQualified(processResult, 1, 1);
    checkRemarkIsPresent(processResult, TestSolution.NEED_MORE_INFO, RemarkMessageStore.MANUAL_CHECK_ON_ELEMENTS_MSG, HtmlElementStore.DATALIST_ELEMENT, 1, new ImmutablePair(ARIA_LABELLEDBY_ATTR, "aria-labelledby-id-for-DATALIST"));
    // ----------------------------------------------------------------------
    // ------------------------------3NMI-06---------------------------------
    // ----------------------------------------------------------------------
    processResult = processPageTest("Rgaa40.Test.11.2.4-3NMI-06");
    checkResultIsPreQualified(processResult, 3, 3);
    checkRemarkIsPresent(processResult, TestSolution.NEED_MORE_INFO, RemarkMessageStore.MANUAL_CHECK_ON_ELEMENTS_MSG, HtmlElementStore.PROGRESS_ELEMENT, 1, new ImmutablePair(ARIA_LABELLEDBY_ATTR, "aria-labelledby-id-for-PROGRESS"));
    checkRemarkIsPresent(processResult, TestSolution.NEED_MORE_INFO, RemarkMessageStore.MANUAL_CHECK_ON_ELEMENTS_MSG, HtmlElementStore.OUTPUT_ELEMENT, 2, new ImmutablePair(ARIA_LABELLEDBY_ATTR, "aria-labelledby-id-for-OUTPUT"));
    checkRemarkIsPresent(processResult, TestSolution.NEED_MORE_INFO, RemarkMessageStore.MANUAL_CHECK_ON_ELEMENTS_MSG, HtmlElementStore.METER_ELEMENT, 3, new ImmutablePair(ARIA_LABELLEDBY_ATTR, "aria-labelledby-id-for-METER"));
    // ----------------------------------------------------------------------
    // ------------------------------3NMI-07---------------------------------
    // ----------------------------------------------------------------------
    processResult = processPageTest("Rgaa40.Test.11.2.4-3NMI-07");
    checkResultIsPreQualified(processResult, 11, 11);
    HashMap<Integer, String> mapRoleAttribute = new HashMap<Integer, String>();
    mapRoleAttribute.put(1, "checkbox");
    mapRoleAttribute.put(2, "combobox");
    mapRoleAttribute.put(3, "listbox");
    mapRoleAttribute.put(4, "progressbar");
    mapRoleAttribute.put(5, "option");
    mapRoleAttribute.put(6, "radio");
    mapRoleAttribute.put(7, "searchbox");
    mapRoleAttribute.put(8, "slider");
    mapRoleAttribute.put(9, "spinbutton");
    mapRoleAttribute.put(10, "switch");
    mapRoleAttribute.put(11, "textbox");
    for (Map.Entry item : mapRoleAttribute.entrySet()) {
        int position = ((int) item.getKey());
        checkRemarkIsPresent(processResult, TestSolution.NEED_MORE_INFO, RemarkMessageStore.MANUAL_CHECK_ON_ELEMENTS_MSG, HtmlElementStore.DIV_ELEMENT, position, new ImmutablePair(ARIA_LABELLEDBY_ATTR, "aria-labelledby-id-for-ROLE-" + item.getValue()));
    }
    // ----------------------------------------------------------------------
    // ------------------------------3NMI-08---------------------------------
    // ----------------------------------------------------------------------
    processResult = processPageTest("Rgaa40.Test.11.2.4-3NMI-08");
    checkResultIsPreQualified(processResult, 1, 1);
    checkRemarkIsPresent(processResult, TestSolution.NEED_MORE_INFO, RemarkMessageStore.MANUAL_CHECK_ON_ELEMENTS_MSG, HtmlElementStore.INPUT_ELEMENT, 1, new ImmutablePair(ARIA_LABELLEDBY_ATTR, "aria-labelledby-for-input-without-parent-form-tag"));
    checkRemarkIsPresent(processResult, TestSolution.NEED_MORE_INFO, RemarkMessageStore.MANUAL_CHECK_ON_ELEMENTS_MSG, HtmlElementStore.INPUT_ELEMENT, 1, new ImmutablePair(ARIA_LABELLEDBY_ATTR, "aria-labelledby1 aria-labelledby2 aria-labelledby-for-input-without-parent-form-tag"));
    // ----------------------------------------------------------------------
    // ------------------------------4NA-01----------------------------------
    // ----------------------------------------------------------------------
    checkResultIsNotApplicable(processPageTest("Rgaa40.Test.11.2.4-4NA-01"));
    // ----------------------------------------------------------------------
    // ------------------------------4NA-02----------------------------------
    // ----------------------------------------------------------------------
    checkResultIsNotApplicable(processPageTest("Rgaa40.Test.11.2.4-4NA-02"));
    // ----------------------------------------------------------------------
    // ------------------------------4NA-03----------------------------------
    // ----------------------------------------------------------------------
    checkResultIsNotApplicable(processPageTest("Rgaa40.Test.11.2.4-4NA-03"));
    // ----------------------------------------------------------------------
    // ------------------------------4NA-04----------------------------------
    // ----------------------------------------------------------------------
    checkResultIsNotApplicable(processPageTest("Rgaa40.Test.11.2.4-4NA-04"));
    // ----------------------------------------------------------------------
    // ------------------------------4NA-05----------------------------------
    // ----------------------------------------------------------------------
    checkResultIsNotApplicable(processPageTest("Rgaa40.Test.11.2.4-4NA-05"));
    // ----------------------------------------------------------------------
    // ------------------------------4NA-06----------------------------------
    // ----------------------------------------------------------------------
    checkResultIsNotApplicable(processPageTest("Rgaa40.Test.11.2.4-4NA-06"));
    // ----------------------------------------------------------------------
    // ------------------------------4NA-07----------------------------------
    // ----------------------------------------------------------------------
    checkResultIsNotApplicable(processPageTest("Rgaa40.Test.11.2.4-4NA-07"));
    // ----------------------------------------------------------------------
    // ------------------------------4NA-08----------------------------------
    // ----------------------------------------------------------------------
    checkResultIsNotApplicable(processPageTest("Rgaa40.Test.11.2.4-4NA-08"));
}
Also used : ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) HashMap(java.util.HashMap) ProcessResult(org.asqatasun.entity.audit.ProcessResult) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

List (java.util.List)30 HashMap (java.util.HashMap)24 Map (java.util.Map)24 ArrayList (java.util.ArrayList)23 Collectors (java.util.stream.Collectors)21 StringUtils (org.apache.commons.lang3.StringUtils)20 LoggerFactory (org.slf4j.LoggerFactory)17 Pair (org.apache.commons.lang3.tuple.Pair)16 Logger (org.slf4j.Logger)16 Set (java.util.Set)15 IOException (java.io.IOException)14 Optional (java.util.Optional)12 Range (org.apache.commons.lang3.Range)11 Test (org.junit.jupiter.api.Test)11 java.util (java.util)10 Date (java.util.Date)10 Lists (com.google.common.collect.Lists)9 HashSet (java.util.HashSet)9 ExecutorService (java.util.concurrent.ExecutorService)9 Collection (java.util.Collection)8