@Before public void setUp() throws Exception { this.conf = new Configuration(); this.keyValues = ImmutableMap.of("k1", "v1", "k2", "v2"); this.key = "my_conf_key"; }
/** * Get all of the values. If reset is true, we will reset the all AtomicLongs back to 0. * @param reset whether to reset the AtomicLongs to 0. * @return A Map of String -> Long for metrics */ public Map<String, Long> getMetricsMap(boolean reset) { // Create a builder ImmutableMap.Builder<String, Long> builder = ImmutableMap.builder(); for (Map.Entry<String, AtomicLong> e : this.counters.entrySet()) { long value = reset ? e.getValue().getAndSet(0) : e.getValue().get(); builder.put(e.getKey(), value); } // Build the immutable map so that people can't mess around with it. return builder.build(); } }
/** * Get the znode string corresponding to a replicaId * @param replicaId * @return znode */ public String getZNodeForReplica(int replicaId) { // return a newly created path but don't update the cache of paths // This is mostly needed for tests that attempt to create meta replicas // from outside the master return Optional.ofNullable(metaReplicaZNodes.get(replicaId)) .orElseGet(() -> metaReplicaZNodes.get(DEFAULT_REPLICA_ID) + "-" + replicaId); }
@Override public void reduce(ImmutableBytesWritable key, Iterator<Put> values, OutputCollector<ImmutableBytesWritable, Put> output, Reporter reporter) throws IOException { String strKey = Bytes.toString(key.get()); List<Put> result = new ArrayList<>(); while (values.hasNext()) result.add(values.next()); if (relation.keySet().contains(strKey)) { Set<String> set = relation.get(strKey); if (set != null) { assertEquals(set.size(), result.size()); } else { throwAccertionError("Test infrastructure error: set is null"); } } else { throwAccertionError("Test infrastructure error: key not found in map"); } }
@Override public CompletableFuture<RegionLocations> getMetaRegionLocation() { CompletableFuture<RegionLocations> future = new CompletableFuture<>(); HRegionLocation[] locs = new HRegionLocation[znodePaths.metaReplicaZNodes.size()]; MutableInt remaining = new MutableInt(locs.length); znodePaths.metaReplicaZNodes.forEach((replicaId, path) -> { if (replicaId == DEFAULT_REPLICA_ID) { getAndConvert(path, ZKAsyncRegistry::getMetaProto).whenComplete((proto, error) -> {
@Test public void testSubset() throws Exception { Configuration conf = HBaseConfiguration.create(); // subset is used in TableMapReduceUtil#initCredentials to support different security // configurations between source and destination clusters, so we'll use that as an example String prefix = "hbase.mapred.output."; conf.set("hbase.security.authentication", "kerberos"); conf.set("hbase.regionserver.kerberos.principal", "hbasesource"); HBaseConfiguration.setWithPrefix(conf, prefix, ImmutableMap.of( "hbase.regionserver.kerberos.principal", "hbasedest", "", "shouldbemissing") .entrySet()); Configuration subsetConf = HBaseConfiguration.subset(conf, prefix); assertNull(subsetConf.get(prefix + "hbase.regionserver.kerberos.principal")); assertEquals("hbasedest", subsetConf.get("hbase.regionserver.kerberos.principal")); assertNull(subsetConf.get("hbase.security.authentication")); assertNull(subsetConf.get("")); Configuration mergedConf = HBaseConfiguration.create(conf); HBaseConfiguration.merge(mergedConf, subsetConf); assertEquals("hbasedest", mergedConf.get("hbase.regionserver.kerberos.principal")); assertEquals("kerberos", mergedConf.get("hbase.security.authentication")); assertEquals("shouldbemissing", mergedConf.get(prefix)); }
= ImmutableMap.<Integer, ImmutableBytesWritable>builder() .put(-1, new ImmutableBytesWritable(Bytes.fromHex("714cb10a9e3b5569852980edd8c6ca2f"))) .put(5, new ImmutableBytesWritable(Bytes.fromHex("28d961d9252ce8f8d44a07b38d3e1d96"))) if (!expectedHashes.equals(actualHashes)) { LOG.error("Diff: " + Maps.difference(expectedHashes, actualHashes));
Object readResolve() { return map.entrySet(); }
/** * Returns an immutable set of the valid column keys, including those that * are associated with null values only. * * @return immutable set of column keys */ @Override public ImmutableSet<C> columnKeySet() { return columnKeyToIndex.keySet(); }
this.rowKeyToIndex = Maps.indexMap(rowSpace); this.columnKeyToIndex = Maps.indexMap(columnSpace); rowCounts = new int[rowKeyToIndex.size()]; columnCounts = new int[columnKeyToIndex.size()]; int[] cellRowIndices = new int[cellList.size()]; int[] cellColumnIndices = new int[cellList.size()]; R rowKey = cell.getRowKey(); C columnKey = cell.getColumnKey(); int rowIndex = rowKeyToIndex.get(rowKey); int columnIndex = columnKeyToIndex.get(columnKey); V existingValue = values[rowIndex][columnIndex]; checkArgument(existingValue == null, "duplicate key: (%s, %s)", rowKey, columnKey);
@Override public boolean isEmpty() { return size() == 0; }
@Override public int hashCode() { /* * The sum of the sums of the hash codes in each subset is just the sum of * each input element's hash code times the number of sets that element * appears in. Each element appears in exactly half of the 2^n sets, so: */ return inputSet.keySet().hashCode() << (inputSet.size() - 1); }
@Override public boolean equals(@Nullable Object object) { if (object instanceof ExplicitOrdering) { ExplicitOrdering<?> that = (ExplicitOrdering<?>) object; return this.rankMap.equals(that.rankMap); } return false; }
@Override public void forEach(Consumer<? super K> action) { checkNotNull(action); map.forEach((k, v) -> action.accept(k)); }
/** * Returns a multimap view of the map. * * @since 14.0 */ public ImmutableSetMultimap<K, V> asMultimap() { if (isEmpty()) { return ImmutableSetMultimap.of(); } ImmutableSetMultimap<K, V> result = multimapView; return (result == null) ? (multimapView = new ImmutableSetMultimap<>(new MapViewOfValuesAsSingletonSets(), size(), null)) : result; }
= ImmutableMap.<Integer, ImmutableBytesWritable>builder() .put(-1, new ImmutableBytesWritable(Bytes.fromHex("714cb10a9e3b5569852980edd8c6ca2f"))) .put(5, new ImmutableBytesWritable(Bytes.fromHex("28d961d9252ce8f8d44a07b38d3e1d96"))) if (!expectedHashes.equals(actualHashes)) { LOG.error("Diff: " + Maps.difference(expectedHashes, actualHashes));
@Test public void testSubset() throws Exception { Configuration conf = HBaseConfiguration.create(); // subset is used in TableMapReduceUtil#initCredentials to support different security // configurations between source and destination clusters, so we'll use that as an example String prefix = "hbase.mapred.output."; conf.set("hbase.security.authentication", "kerberos"); conf.set("hbase.regionserver.kerberos.principal", "hbasesource"); HBaseConfiguration.setWithPrefix(conf, prefix, ImmutableMap.of( "hbase.regionserver.kerberos.principal", "hbasedest", "", "shouldbemissing") .entrySet()); Configuration subsetConf = HBaseConfiguration.subset(conf, prefix); assertNull(subsetConf.get(prefix + "hbase.regionserver.kerberos.principal")); assertEquals("hbasedest", subsetConf.get("hbase.regionserver.kerberos.principal")); assertNull(subsetConf.get("hbase.security.authentication")); assertNull(subsetConf.get("")); Configuration mergedConf = HBaseConfiguration.create(conf); HBaseConfiguration.merge(mergedConf, subsetConf); assertEquals("hbasedest", mergedConf.get("hbase.regionserver.kerberos.principal")); assertEquals("kerberos", mergedConf.get("hbase.security.authentication")); assertEquals("shouldbemissing", mergedConf.get(prefix)); }