use of com.google.common.annotations.VisibleForTesting in project presto by prestodb.
the class EventListenerManager method setConfiguredEventListener.
@VisibleForTesting
protected void setConfiguredEventListener(String name, Map<String, String> properties) {
requireNonNull(name, "name is null");
requireNonNull(properties, "properties is null");
log.info("-- Loading event listener --");
EventListenerFactory eventListenerFactory = eventListenerFactories.get(name);
checkState(eventListenerFactory != null, "Event listener %s is not registered", name);
EventListener eventListener = eventListenerFactory.create(ImmutableMap.copyOf(properties));
this.configuredEventListener.set(Optional.of(eventListener));
log.info("-- Loaded event listener %s --", name);
}
use of com.google.common.annotations.VisibleForTesting in project presto by prestodb.
the class InternalResourceGroupManager method setConfigurationManager.
@VisibleForTesting
public void setConfigurationManager(String name, Map<String, String> properties) {
requireNonNull(name, "name is null");
requireNonNull(properties, "properties is null");
log.info("-- Loading resource group configuration manager --");
ResourceGroupConfigurationManagerFactory configurationManagerFactory = configurationManagerFactories.get(name);
checkState(configurationManagerFactory != null, "Resource group configuration manager %s is not registered", name);
ResourceGroupConfigurationManager configurationManager = configurationManagerFactory.create(ImmutableMap.copyOf(properties), () -> memoryPoolManager);
checkState(this.configurationManager.compareAndSet(null, configurationManager), "configurationManager already set");
log.info("-- Loaded resource group configuration manager %s --", name);
}
use of com.google.common.annotations.VisibleForTesting in project presto by prestodb.
the class HeartbeatFailureDetector method updateMonitoredServices.
@VisibleForTesting
void updateMonitoredServices() {
Set<ServiceDescriptor> online = selector.selectAllServices().stream().filter(descriptor -> !nodeInfo.getNodeId().equals(descriptor.getNodeId())).collect(toImmutableSet());
Set<UUID> onlineIds = online.stream().map(ServiceDescriptor::getId).collect(toImmutableSet());
// make sure only one thread is updating the registrations
synchronized (tasks) {
// 1. remove expired tasks
List<UUID> expiredIds = tasks.values().stream().filter(MonitoringTask::isExpired).map(MonitoringTask::getService).map(ServiceDescriptor::getId).collect(toImmutableList());
tasks.keySet().removeAll(expiredIds);
// 2. disable offline services
tasks.values().stream().filter(task -> !onlineIds.contains(task.getService().getId())).forEach(MonitoringTask::disable);
// 3. create tasks for new services
Set<ServiceDescriptor> newServices = online.stream().filter(service -> !tasks.keySet().contains(service.getId())).collect(toImmutableSet());
for (ServiceDescriptor service : newServices) {
URI uri = getHttpUri(service);
if (uri != null) {
tasks.put(service.getId(), new MonitoringTask(service, uri));
}
}
// 4. enable all online tasks (existing plus newly created)
tasks.values().stream().filter(task -> onlineIds.contains(task.getService().getId())).forEach(MonitoringTask::enable);
}
}
use of com.google.common.annotations.VisibleForTesting in project presto by prestodb.
the class DecimalAverageAggregation method average.
@VisibleForTesting
public static BigDecimal average(LongDecimalWithOverflowAndLongState state, DecimalType type) {
BigDecimal sum = new BigDecimal(Decimals.decodeUnscaledValue(state.getLongDecimal()), type.getScale());
BigDecimal count = BigDecimal.valueOf(state.getLong());
if (state.getOverflow() != 0) {
BigInteger overflowMultiplier = TWO.shiftLeft(UNSCALED_DECIMAL_128_SLICE_LENGTH * 8 - 2);
BigInteger overflow = overflowMultiplier.multiply(BigInteger.valueOf(state.getOverflow()));
sum = sum.add(new BigDecimal(overflow));
}
return sum.divide(count, type.getScale(), ROUND_HALF_UP);
}
use of com.google.common.annotations.VisibleForTesting in project presto by prestodb.
the class ColorFunctions method parseRgb.
@VisibleForTesting
static int parseRgb(Slice color) {
if (color.length() != 4 || color.getByte(0) != '#') {
return -1;
}
int red = Character.digit((char) color.getByte(1), 16);
int green = Character.digit((char) color.getByte(2), 16);
int blue = Character.digit((char) color.getByte(3), 16);
if (red == -1 || green == -1 || blue == -1) {
return -1;
}
// replicate the nibbles to turn a color of the form #rgb => #rrggbb (css semantics)
red = (red << 4) | red;
green = (green << 4) | green;
blue = (blue << 4) | blue;
return (int) rgb(red, green, blue);
}
Aggregations