com.google.common.collect.Lists Java Examples

The following examples show how to use com.google.common.collect.Lists. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OzoneManagerRequestHandler.java    From hadoop-ozone with Apache License 2.0 6 votes vote down vote up
private ListVolumeResponse listVolumes(ListVolumeRequest request)
    throws IOException {
  ListVolumeResponse.Builder resp = ListVolumeResponse.newBuilder();
  List<OmVolumeArgs> result = Lists.newArrayList();

  if (request.getScope()
      == ListVolumeRequest.Scope.VOLUMES_BY_USER) {
    result = impl.listVolumeByUser(request.getUserName(),
        request.getPrefix(), request.getPrevKey(), request.getMaxKeys());
  } else if (request.getScope()
      == ListVolumeRequest.Scope.VOLUMES_BY_CLUSTER) {
    result =
        impl.listAllVolumes(request.getPrefix(), request.getPrevKey(),
            request.getMaxKeys());
  }

  result.forEach(item -> resp.addVolumeInfo(item.getProtobuf()));

  return resp.build();
}
 
Example #2
Source File: ActivityRuleService.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@Override
public List<ActivityRuleEntity> getActivityRule(ActivityRuleEntity activityRuleEntity) throws DTSAdminException {
    ActivityRuleDO activityRuleDO = ActivityRuleHelper.toActivityRuleDO(activityRuleEntity);
    ActivityRuleDOExample example = new ActivityRuleDOExample();
    Criteria criteria = example.createCriteria();
    criteria.andIsDeletedIsNotNull();
    if (StringUtils.isNotEmpty(activityRuleDO.getBizType())) {
        criteria.andBizTypeLike(activityRuleDO.getBizType());
    }
    if (StringUtils.isNotEmpty(activityRuleDO.getApp())) {
        criteria.andAppLike(activityRuleDO.getApp());
    }
    if (StringUtils.isNotEmpty(activityRuleDO.getAppCname())) {
        criteria.andAppCnameLike(activityRuleDO.getAppCname());
    }
    example.setOrderByClause("app,biz_type");
    List<ActivityRuleDO> lists = activityRuleDOMapper.selectByExample(example);
    if (CollectionUtils.isEmpty(lists)) {
        return Lists.newArrayList();
    }
    List<ActivityRuleEntity> entities = Lists.newArrayList();
    for (ActivityRuleDO an : lists) {
        entities.add(ActivityRuleHelper.toActivityRuleEntity(an));
    }
    return entities;
}
 
Example #3
Source File: ConfigConstraints.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
protected Iterable<ConfigKey<?>> validateAll() {
    List<ConfigKey<?>> violating = Lists.newLinkedList();
    Iterable<ConfigKey<?>> configKeys = getBrooklynObjectTypeConfigKeys();
    LOG.trace("Checking config keys on {}: {}", getBrooklynObject(), configKeys);
    for (ConfigKey<?> configKey : configKeys) {
        BrooklynObjectInternal.ConfigurationSupportInternal configInternal = getConfigurationSupportInternal();
        // getNonBlocking method coerces the value to the config key's type.
        Maybe<?> maybeValue = configInternal.getNonBlocking(configKey);
        if (maybeValue.isPresent()) {
            // Cast is safe because the author of the constraint on the config key had to
            // keep its type to Predicte<? super T>, where T is ConfigKey<T>.
            ConfigKey<Object> ck = (ConfigKey<Object>) configKey;
            if (!isValueValid(ck, maybeValue.get())) {
                violating.add(configKey);
            }
        } else {
            // absent means did not resolve in time or not coercible;
            // code will return `Maybe.of(null)` if it is unset,
            // and coercion errors are handled when the value is _set_ or _needed_
            // (this allows us to deal with edge cases where we can't *immediately* coerce)
        }
    }
    return violating;
}
 
Example #4
Source File: PostgreSQLViewNotificationParserTest.java    From binnavi with Apache License 2.0 6 votes vote down vote up
@Test
public void testViewInform3() throws CouldntLoadDataException {
  final boolean starState2 = true;
  view.getConfiguration().setStaredInternal(starState2);
  assertEquals(starState2, view.getConfiguration().isStared());

  final ViewNotificationContainer container =
      new ViewNotificationContainer(view.getConfiguration().getId(),
          Optional.fromNullable(view),
          Optional.<Integer>absent(),
          Optional.<INaviModule>absent(),
          Optional.<INaviProject>absent(),
          "UPDATE");

  final PostgreSQLViewNotificationParser parser = new PostgreSQLViewNotificationParser();
  parser.inform(Lists.<ViewNotificationContainer>newArrayList(container), provider);

  assertEquals(false, view.getConfiguration().isStared());
}
 
Example #5
Source File: HousekeepingCleanupLocationManagerTest.java    From circus-train with Apache License 2.0 6 votes vote down vote up
@Test
public void scheduleLocationsMultipleAddsAlternate() throws Exception {
  HousekeepingCleanupLocationManager manager = new HousekeepingCleanupLocationManager(EVENT_ID, housekeepingListener,
      replicaCatalogListener, DATABASE, TABLE);
  String pathEventId = "pathEventId";
  Path path1 = new Path("location1");
  Path path2 = new Path("location2");

  manager.addCleanupLocation(pathEventId, path1);
  manager.scheduleLocations();
  verify(housekeepingListener).cleanUpLocation(EVENT_ID, pathEventId, path1, DATABASE, TABLE);
  List<URI> uris = Lists.newArrayList(path1.toUri());
  verify(replicaCatalogListener).deprecatedReplicaLocations(uris);

  manager.addCleanupLocation(pathEventId, path2);
  manager.scheduleLocations();
  verify(housekeepingListener).cleanUpLocation(EVENT_ID, pathEventId, path2, DATABASE, TABLE);
  List<URI> urisSecondCleanup = Lists.newArrayList(path2.toUri());
  verify(replicaCatalogListener).deprecatedReplicaLocations(urisSecondCleanup);
}
 
Example #6
Source File: CienaWaveserverDeviceDescription.java    From onos with Apache License 2.0 6 votes vote down vote up
public static PortDescription parseWaveServerCienaOchPorts(long portNumber,
                                                           HierarchicalConfiguration config,
                                                           SparseAnnotations annotations) {
    final List<String> tunableType = Lists.newArrayList("performance-optimized", "accelerated");
    final String flexGrid = "flex-grid";
    final String state = "properties.transmitter.state";
    final String tunable = "properties.modem.tx-tuning-mode";
    final String spacing = "properties.line-system.wavelength-spacing";
    final String frequency = "properties.transmitter.frequency.value";

    boolean isEnabled = config.getString(state).equals(ENABLED);
    boolean isTunable = tunableType.contains(config.getString(tunable));

    GridType gridType = config.getString(spacing).equals(flexGrid) ? GridType.FLEX : null;
    ChannelSpacing chSpacing = gridType == GridType.FLEX ? ChannelSpacing.CHL_6P25GHZ : null;

    //Working in Ghz //(Nominal central frequency - 193.1)/channelSpacing = spacingMultiplier
    final int baseFrequency = 193100;
    long spacingFrequency = chSpacing == null ? baseFrequency : chSpacing.frequency().asHz();
    int spacingMult = ((int) (toGbps(((int) config.getDouble(frequency) -
            baseFrequency)) / toGbpsFromHz(spacingFrequency))); //FIXME is there a better way ?

    return ochPortDescription(PortNumber.portNumber(portNumber), isEnabled, OduSignalType.ODU4, isTunable,
                              new OchSignal(gridType, chSpacing, spacingMult, 1), annotations);
}
 
Example #7
Source File: UserServiceImpl.java    From SpringBoot-Dubbo-Docker-Jenkins with Apache License 2.0 6 votes vote down vote up
/**
 * 根据userState将userId分组
 * @param userStateReqs 修改用户状态的请求
 * @return 分组后结果(key:用户状态、value:该状态下对应的userid列表)
 */
private Map<Integer, List<String>> groupUserIdByUserState(BatchReq<UserStateReq> userStateReqs) {
    // 创建结果集
    Map<Integer, List<String>> userStateMap = Maps.newHashMap();

    // 遍历UserStateEnum
    if (UserStateEnum.values().length > 0) {
        for (UserStateEnum userStateEnum : UserStateEnum.values()) {
            // 获取当前用户状态下的所有userid
            List<String> userIdList = Lists.newArrayList();
            if (CollectionUtils.isNotEmpty(userStateReqs.getReqList())) {
                for (UserStateReq userStateReq : userStateReqs.getReqList()) {
                    if (userStateReq.getUserState() == userStateEnum.getCode()) {
                        userIdList.add(userStateReq.getUserId());
                    }
                }
                userStateMap.put(userStateEnum.getCode(), userIdList);
            }
        }
    }

    return userStateMap;
}
 
Example #8
Source File: ProduceRequestHandler.java    From joyqueue with Apache License 2.0 6 votes vote down vote up
protected void splitByPartitionGroup(TopicConfig topicConfig, TopicName topic, Producer producer, byte[] clientAddress, Traffic traffic,
                            ProduceRequest.PartitionRequest partitionRequest, Map<Integer, ProducePartitionGroupRequest> partitionGroupRequestMap) {
    PartitionGroup partitionGroup = topicConfig.fetchPartitionGroupByPartition((short) partitionRequest.getPartition());
    ProducePartitionGroupRequest producePartitionGroupRequest = partitionGroupRequestMap.get(partitionGroup.getGroup());

    if (producePartitionGroupRequest == null) {
        producePartitionGroupRequest = new ProducePartitionGroupRequest(Lists.newLinkedList(), Lists.newLinkedList(),
                Lists.newLinkedList(), Maps.newHashMap(), Maps.newHashMap());
        partitionGroupRequestMap.put(partitionGroup.getGroup(), producePartitionGroupRequest);
    }

    List<BrokerMessage> brokerMessages = Lists.newLinkedList();
    for (KafkaBrokerMessage message : partitionRequest.getMessages()) {
        BrokerMessage brokerMessage = KafkaMessageConverter.toBrokerMessage(producer.getTopic(), partitionRequest.getPartition(), producer.getApp(), clientAddress, message);
        brokerMessages.add(brokerMessage);
    }

    traffic.record(topic.getFullName(), partitionRequest.getTraffic(), partitionRequest.getSize());
    producePartitionGroupRequest.getPartitions().add(partitionRequest.getPartition());
    producePartitionGroupRequest.getMessages().addAll(brokerMessages);
    producePartitionGroupRequest.getMessageMap().put(partitionRequest.getPartition(), brokerMessages);
    producePartitionGroupRequest.getKafkaMessages().addAll(partitionRequest.getMessages());
    producePartitionGroupRequest.getKafkaMessageMap().put(partitionRequest.getPartition(), partitionRequest.getMessages());
}
 
Example #9
Source File: QuerySegmentationFactoryTest.java    From elasticsearch-reindex-tool with Apache License 2.0 6 votes vote down vote up
@Test
@Parameters({ "1.0, 2.0" })
public void shouldCreateDoubleFieldSegmentation(double lowerBound, double upperBound) throws Exception {
  //given
  ReindexCommand command = mock(ReindexCommand.class);
  String fieldName = "fieldName";
  when(command.getSegmentationField()).thenReturn(fieldName);
  when(command.getSegmentationThresholds()).thenReturn(Lists.newArrayList(lowerBound, upperBound));
  //when
  QuerySegmentation querySegmentation = QuerySegmentationFactory.create(command);
  //then
  assertThat(querySegmentation)
      .isInstanceOf(DoubleFieldSegmentation.class)
      .hasFileName(fieldName)
      .hasSegmentsCount(1);
  RangeSegmentAssert.assertThat((RangeSegment) (querySegmentation.getThreshold(0).get()))
      .hasLowerOpenBound(lowerBound)
      .hasUpperBound(upperBound);
}
 
Example #10
Source File: DynamoDBStorageHandlerTest.java    From emr-dynamodb-connector with Apache License 2.0 6 votes vote down vote up
@Test
public void testCheckTableSchemaTypeValid() throws MetaException {
  TableDescription description = getHashRangeTable();

  Table table = new Table();
  Map<String, String> parameters = Maps.newHashMap();
  parameters.put(DynamoDBConstants.DYNAMODB_COLUMN_MAPPING, "col1:dynamo_col1$," +
      "col2:dynamo_col2#,hashKey:hashKey");
  table.setParameters(parameters);
  StorageDescriptor sd = new StorageDescriptor();
  List<FieldSchema> cols = Lists.newArrayList();
  cols.add(new FieldSchema("col1", "string", ""));
  cols.add(new FieldSchema("col2", "bigint", ""));
  cols.add(new FieldSchema("hashKey", "string", ""));
  sd.setCols(cols);
  table.setSd(sd);
  // This check is expected to pass for the given input
  storageHandler.checkTableSchemaType(description, table);
}
 
Example #11
Source File: QuorumJournalManager.java    From hadoop with Apache License 2.0 6 votes vote down vote up
private static List<InetSocketAddress> getLoggerAddresses(URI uri)
    throws IOException {
  String authority = uri.getAuthority();
  Preconditions.checkArgument(authority != null && !authority.isEmpty(),
      "URI has no authority: " + uri);
  
  String[] parts = StringUtils.split(authority, ';');
  for (int i = 0; i < parts.length; i++) {
    parts[i] = parts[i].trim();
  }

  if (parts.length % 2 == 0) {
    LOG.warn("Quorum journal URI '" + uri + "' has an even number " +
        "of Journal Nodes specified. This is not recommended!");
  }
  
  List<InetSocketAddress> addrs = Lists.newArrayList();
  for (String addr : parts) {
    addrs.add(NetUtils.createSocketAddr(
        addr, DFSConfigKeys.DFS_JOURNALNODE_RPC_PORT_DEFAULT));
  }
  return addrs;
}
 
Example #12
Source File: TypeScriptGeneratorTest.java    From clutz with MIT License 6 votes vote down vote up
@Parameters(name = "Test {index}: {0}")
public static Iterable<SingleTestConfig> testCases() throws IOException {
  List<SingleTestConfig> configs = Lists.newArrayList();
  List<File> testInputFiles =
      getTestInputFiles(DeclarationGeneratorTest.JS_NO_EXTERNS_OR_ZIP, singleTestPath);
  File inputFileRoot = getTestDirPath(singleTestPath).toFile().getCanonicalFile();
  for (File file : testInputFiles) {
    TestInput input =
        new TestInput(
            inputFileRoot.getAbsolutePath(), TestUtil.getRelativePathTo(file, inputFileRoot));

    configs.add(new SingleTestConfig(ExperimentTracker.withoutExperiments(), input));

    /*
     * To specify that another experiment should be used, add the Experiment enum
     * value for that experiment in the withExperiments() method.
     */
    // To enable testing an experiment, replace SOME_EXPERIMENT with the experiment
    // enum value below and uncomment the next lines.
    // configs.add(
    //     new SingleTestConfig(
    //         ExperimentTracker.withExperiments(Experiment.SOME_EXPERIMENT), input));
  }
  return configs;
}
 
Example #13
Source File: FujitsuT100DeviceDescription.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Parses a configuration and returns a set of ports for the fujitsu T100.
 *
 * @param cfg a hierarchical configuration
 * @return a list of port descriptions
 */
private static List<PortDescription> parseFujitsuT100Ports(HierarchicalConfiguration cfg) {
    AtomicInteger counter = new AtomicInteger(1);
    List<PortDescription> portDescriptions = Lists.newArrayList();
    List<HierarchicalConfiguration> subtrees =
            cfg.configurationsAt("data.interfaces.interface");
    for (HierarchicalConfiguration portConfig : subtrees) {
        if (!portConfig.getString("name").contains("LCN") &&
                !portConfig.getString("name").contains("LMP") &&
                "ianaift:ethernetCsmacd".equals(portConfig.getString("type"))) {
            portDescriptions.add(parseT100OduPort(portConfig, counter.getAndIncrement()));
        } else if ("ianaift:otnOtu".equals(portConfig.getString("type"))) {
            portDescriptions.add(parseT100OchPort(portConfig, counter.getAndIncrement()));
        }
    }
    return portDescriptions;
}
 
Example #14
Source File: DistributedDoubleBarrier.java    From curator with Apache License 2.0 6 votes vote down vote up
private List<String> filterAndSortChildren(List<String> children)
{
    Iterable<String> filtered = Iterables.filter
    (
        children,
        new Predicate<String>()
        {
            @Override
            public boolean apply(String name)
            {
                return !name.equals(READY_NODE);
            }
        }
    );

    ArrayList<String> filteredList = Lists.newArrayList(filtered);
    Collections.sort(filteredList);
    return filteredList;
}
 
Example #15
Source File: TestSchemaCommandMerge.java    From kite with Apache License 2.0 6 votes vote down vote up
@Test
public void testSchemaMerge() throws Exception {
  command.datasets = Lists.newArrayList(
      schemaFile.toString(),
      "resource:schema/user.avsc");
  int rc = command.run();
  Assert.assertEquals("Should return success code", 0, rc);

  Schema merged = SchemaBuilder.record("user").fields()
      .optionalLong("id") // required in one, missing in the other
      .requiredString("username")
      .requiredString("email")
      .endRecord();

  verify(console).info(argThat(TestUtil.matchesSchema(merged)));
  verifyNoMoreInteractions(console);
}
 
Example #16
Source File: AccumuloEntityStoreIT.java    From accumulo-recipes with Apache License 2.0 6 votes vote down vote up
@Test
public void test_createAndDeleteEntities() throws Exception {

    for (int i = 0; i < 10; i++) {
        Entity entity = EntityBuilder.create("type", "type_"+i)
                .attr(new Attribute("key1", "val1", meta))
                .attr(new Attribute("key2", "val2", meta))
                .build();

        store.save(singleton(entity));
    }
    store.flush();

    List<EntityIdentifier> typesAndIds = Arrays.asList(new EntityIdentifier("type", "type_0"),
            new EntityIdentifier("type", "type_1"), new EntityIdentifier("type", "type_2"));
    Iterable<Entity> actualEntities = store.get(typesAndIds, null, new Auths("A"));
    assertEquals(3,Iterables.size(actualEntities));

    store.delete(Lists.newArrayList(store.get(typesAndIds,new Auths("A"))));
    store.flush();

    Iterable<Entity> actualEntitiesAfterDelete = store.get(typesAndIds, null, new Auths("A"));
    assertEquals(0,Iterables.size(actualEntitiesAfterDelete));

}
 
Example #17
Source File: PortForwardManagerImpl.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Override
public boolean forgetPortMappings(String publicIpId) {
    List<PortMapping> result = Lists.newArrayList();
    synchronized (mutex) {
        for (Iterator<PortMapping> iter = mappings.values().iterator(); iter.hasNext();) {
            PortMapping m = iter.next();
            if (publicIpId.equals(m.publicIpId)) {
                iter.remove();
                result.add(m);
                emitAssociationDeletedEvent(associationMetadataFromPortMapping(m));
            }
        }
    }
    if (log.isDebugEnabled()) log.debug("cleared all port mappings for "+publicIpId+" - "+result);
    if (!result.isEmpty()) {
        onChanged();
    }
    return !result.isEmpty();
}
 
Example #18
Source File: BusinessObjectDefinitionColumnServiceTest.java    From herd with Apache License 2.0 6 votes vote down vote up
@Test
public void testSearchBusinessObjectDefinitionColumns()
{
    createDatabaseEntitiesForBusinessObjectDefinitionColumnSearchTesting();

    // Search the business object definition columns using all field parameters.
    BusinessObjectDefinitionColumnSearchResponse businessObjectDefinitionColumnSearchResponse = businessObjectDefinitionColumnService
        .searchBusinessObjectDefinitionColumns(new BusinessObjectDefinitionColumnSearchRequest(Lists.newArrayList(
            new BusinessObjectDefinitionColumnSearchFilter(Lists.newArrayList(new BusinessObjectDefinitionColumnSearchKey(BDEF_NAMESPACE, BDEF_NAME))))),
            Sets.newHashSet(SCHEMA_COLUMN_NAME_FIELD, DESCRIPTION_FIELD));

    // Validate the response object.
    assertEquals(new BusinessObjectDefinitionColumnSearchResponse(Lists.newArrayList(
        new BusinessObjectDefinitionColumn(NO_ID, new BusinessObjectDefinitionColumnKey(BDEF_NAMESPACE, BDEF_NAME, BDEF_COLUMN_NAME), COLUMN_NAME,
            BDEF_COLUMN_DESCRIPTION, NO_BUSINESS_OBJECT_DEFINITION_COLUMN_CHANGE_EVENTS),
        new BusinessObjectDefinitionColumn(NO_ID, new BusinessObjectDefinitionColumnKey(BDEF_NAMESPACE, BDEF_NAME, BDEF_COLUMN_NAME_2), COLUMN_NAME_2,
            BDEF_COLUMN_DESCRIPTION_2, NO_BUSINESS_OBJECT_DEFINITION_COLUMN_CHANGE_EVENTS))), businessObjectDefinitionColumnSearchResponse);
}
 
Example #19
Source File: AbstractBundleSubmissionServiceImpl.java    From judgels with GNU General Public License v2.0 6 votes vote down vote up
@Override
public List<BundleSubmission> getBundleSubmissionsByFilters(String orderBy, String orderDir, String authorJid, String problemJid, String containerJid) {
    ImmutableMap.Builder<SingularAttribute<? super SM, ? extends Object>, String> filterColumnsBuilder = ImmutableMap.builder();
    if (authorJid != null) {
        filterColumnsBuilder.put(AbstractBundleSubmissionModel_.createdBy, authorJid);
    }
    if (problemJid != null) {
        filterColumnsBuilder.put(AbstractBundleSubmissionModel_.problemJid, problemJid);
    }
    if (containerJid != null) {
        filterColumnsBuilder.put(AbstractBundleSubmissionModel_.containerJid, containerJid);
    }

    Map<SingularAttribute<? super SM, ? extends Object>, String> filterColumns = filterColumnsBuilder.build();

    List<SM> submissionModels = bundleSubmissionDao.findSortedByFiltersEq(orderBy, orderDir, "", filterColumns, 0, -1);

    return Lists.transform(submissionModels, m -> BundleSubmissionServiceUtils.createSubmissionFromModel(m));
}
 
Example #20
Source File: MethodTracepoint.java    From tracing-framework with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public List<TracepointSpec> getTracepointSpecsForAdvice(AdviceSpec advice) {
    TracepointSpec.Builder tsb = TracepointSpec.newBuilder();
    MethodTracepointSpec.Builder b = tsb.getMethodTracepointBuilder();
    b.setClassName(className);
    b.setMethodName(methodName);
    b.addAllParamClass(Lists.newArrayList(args));
    b.setWhere(interceptAt);
    if (interceptAt == Where.LINENUM) {
        b.setLineNumber(interceptAtLineNumber);
    }
    for (String observedVar : advice.getObserve().getVarList()) {
        b.addAdviceArg(exports.get(observedVar.split("\\.")[1]).getSpec());
    }
    return Lists.<TracepointSpec>newArrayList(tsb.build());
}
 
Example #21
Source File: JdbcAbstractSink.java    From pulsar with Apache License 2.0 5 votes vote down vote up
@Override
public void open(Map<String, Object> config, SinkContext sinkContext) throws Exception {
    jdbcSinkConfig = JdbcSinkConfig.load(config);

    jdbcUrl = jdbcSinkConfig.getJdbcUrl();
    if (jdbcSinkConfig.getJdbcUrl() == null) {
        throw new IllegalArgumentException("Required jdbc Url not set.");
    }

    Properties properties = new Properties();
    String username = jdbcSinkConfig.getUserName();
    String password = jdbcSinkConfig.getPassword();
    if (username != null) {
        properties.setProperty("user", username);
    }
    if (password != null) {
        properties.setProperty("password", password);
    }


    Class.forName(JdbcUtils.getDriverClassName(jdbcSinkConfig.getJdbcUrl()));
    connection = DriverManager.getConnection(jdbcSinkConfig.getJdbcUrl(), properties);
    connection.setAutoCommit(false);
    log.info("Opened jdbc connection: {}, autoCommit: {}", jdbcUrl, connection.getAutoCommit());

    tableName = jdbcSinkConfig.getTableName();
    tableId = JdbcUtils.getTableId(connection, tableName);
    // Init PreparedStatement include insert, delete, update
    initStatement();

    int timeoutMs = jdbcSinkConfig.getTimeoutMs();
    batchSize = jdbcSinkConfig.getBatchSize();
    incomingList = Lists.newArrayList();
    swapList = Lists.newArrayList();
    isFlushing = new AtomicBoolean(false);

    flushExecutor = Executors.newScheduledThreadPool(1);
    flushExecutor.scheduleAtFixedRate(this::flush, timeoutMs, timeoutMs, TimeUnit.MILLISECONDS);
}
 
Example #22
Source File: ListeningCurrentQuotaUpdaterTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
void addedEventShouldIncreaseCurrentQuotaValues() throws Exception {
    MailboxListener.Added added = mock(MailboxListener.Added.class);
    when(added.getMailboxId()).thenReturn(MAILBOX_ID);
    when(added.getMetaData(MessageUid.of(36))).thenReturn(new MessageMetaData(MessageUid.of(36), ModSeq.first(),new Flags(), SIZE, new Date(), new DefaultMessageId()));
    when(added.getMetaData(MessageUid.of(38))).thenReturn(new MessageMetaData(MessageUid.of(38), ModSeq.first(),new Flags(), SIZE, new Date(), new DefaultMessageId()));
    when(added.getUids()).thenReturn(Lists.newArrayList(MessageUid.of(36), MessageUid.of(38)));
    when(added.getUsername()).thenReturn(USERNAME_BENWA);
    when(mockedQuotaRootResolver.getQuotaRootReactive(eq(MAILBOX_ID))).thenReturn(Mono.just(QUOTA_ROOT));
    when(mockedCurrentQuotaManager.increase(QUOTA)).thenAnswer(any -> Mono.empty());

    testee.event(added);

    verify(mockedCurrentQuotaManager).increase(QUOTA);
}
 
Example #23
Source File: GridColumn.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Iterator<OffsetStyle> iterator() {
	List<OffsetStyle> toRemove = Lists.newArrayList();
	for (int i = 1; i < 12; i++) {
		toRemove.add(new OffsetStyle(this.preffix, i));
	}
	return toRemove.iterator();
}
 
Example #24
Source File: TestShuffleVertexManagerBase.java    From tez with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 5000)
public void testZeroSourceTasksWithVertexStateUpdatedFirst() {
  Configuration conf = new Configuration();
  ShuffleVertexManagerBase manager;

  final String mockSrcVertexId1 = "Vertex1";
  final String mockSrcVertexId2 = "Vertex2";
  final String mockSrcVertexId3 = "Vertex3";
  final String mockManagedVertexId = "Vertex4";
  final List<Integer> scheduledTasks = Lists.newLinkedList();

  // source vertices have 0 tasks.
  final VertexManagerPluginContext mockContext = createVertexManagerContext(
      mockSrcVertexId1, 0, mockSrcVertexId2, 0, mockSrcVertexId3, 1,
      mockManagedVertexId, 4, scheduledTasks, null);
  // check initialization
  manager = createManager(conf, mockContext, 0.1f, 0.1f); // Tez notified of reconfig

  verify(mockContext, times(1)).vertexReconfigurationPlanned();
  // source vertices have 0 tasks. so only 1 notification needed. does not trigger scheduling
  // normally this event will not come before onVertexStarted() is called
  manager.onVertexStateUpdated(new VertexStateUpdate(mockSrcVertexId1, VertexState.CONFIGURED));
  manager.onVertexStateUpdated(new VertexStateUpdate(mockSrcVertexId2, VertexState.CONFIGURED));
  manager.onVertexStateUpdated(new VertexStateUpdate(mockSrcVertexId3, VertexState.CONFIGURED));
  verify(mockContext, times(0)).doneReconfiguringVertex(); // no change. will trigger after start
  Assert.assertTrue(scheduledTasks.size() == 0); // no tasks scheduled
  // trigger start and processing of pending notification events
  manager.onVertexStarted(emptyCompletions);
  Assert.assertTrue(manager.bipartiteSources == 2);
  verify(mockContext, times(1)).reconfigureVertex(eq(1), any
      (VertexLocationHint.class), anyMap());
  verify(mockContext, times(1)).doneReconfiguringVertex(); // reconfig done
  Assert.assertTrue(manager.pendingTasks.isEmpty());
  Assert.assertTrue(scheduledTasks.size() == 1); // all tasks scheduled and parallelism changed
}
 
Example #25
Source File: TestShuffleUtils.java    From tez with Apache License 2.0 5 votes vote down vote up
@Test
public void testGenerateOnSpillEvent() throws Exception {
  List<Event> events = Lists.newLinkedList();
  Path indexFile = createIndexFile(10, false);

  boolean finalMergeEnabled = false;
  boolean isLastEvent = false;
  int spillId = 0;
  int physicalOutputs = 10;
  String pathComponent = "/attempt_x_y_0/file.out";
  String auxiliaryService = conf.get(TezConfiguration.TEZ_AM_SHUFFLE_AUXILIARY_SERVICE_ID,
      TezConfiguration.TEZ_AM_SHUFFLE_AUXILIARY_SERVICE_ID_DEFAULT);

  ShuffleUtils.generateEventOnSpill(events, finalMergeEnabled, isLastEvent,
      outputContext, spillId, new TezSpillRecord(indexFile, conf),
          physicalOutputs, true, pathComponent, null, false, auxiliaryService, TezCommonUtils.newBestCompressionDeflater());

  Assert.assertTrue(events.size() == 1);
  Assert.assertTrue(events.get(0) instanceof CompositeDataMovementEvent);

  CompositeDataMovementEvent cdme = (CompositeDataMovementEvent) events.get(0);
  Assert.assertTrue(cdme.getCount() == physicalOutputs);
  Assert.assertTrue(cdme.getSourceIndexStart() == 0);

  ByteBuffer payload = cdme.getUserPayload();
  ShuffleUserPayloads.DataMovementEventPayloadProto dmeProto =
      ShuffleUserPayloads.DataMovementEventPayloadProto.parseFrom(ByteString.copyFrom(payload));

  Assert.assertTrue(dmeProto.getSpillId() == 0);
  Assert.assertTrue(dmeProto.hasLastEvent() && !dmeProto.getLastEvent());

  byte[] emptyPartitions = TezCommonUtils.decompressByteStringToByteArray(dmeProto.getEmptyPartitions());
  BitSet emptyPartitionsBitSet = TezUtilsInternal.fromByteArray(emptyPartitions);
  Assert.assertTrue("emptyPartitionBitSet cardinality (expecting 5) = " + emptyPartitionsBitSet
      .cardinality(), emptyPartitionsBitSet.cardinality() == 5);

  events.clear();

}
 
Example #26
Source File: BaseVariantData.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
public void addJavaSourceFoldersToModel(@NonNull Collection<File> generatedSourceFolders) {
    if (extraGeneratedSourceFolders == null) {
        extraGeneratedSourceFolders = Lists.newArrayList();
    }

    extraGeneratedSourceFolders.addAll(generatedSourceFolders);
}
 
Example #27
Source File: SmtpSessionTest.java    From NioSmtpClient with Apache License 2.0 5 votes vote down vote up
@Test
public void itSupportsOverridingInterceptorsForASingleSend() throws Exception {
  LoggingInterceptor localLog = new LoggingInterceptor();
  CompletableFuture<SmtpClientResponse> future = session.send(ALICE, Lists.newArrayList(BOB, CAROL), smtpContent, localLog);

  assertResponsesMapped(4, future);

  assertThat(log.getLog()).isEqualTo(""); // shared interceptors are not called
  assertThat(localLog.getLog()).isEqualTo("<pipeline MAIL, RCPT, RCPT>, 250 OK 0, 251 OK 1, 252 OK 2, 253 OK 3");
}
 
Example #28
Source File: TestGetPrevPageCliAction.java    From oodt with Apache License 2.0 5 votes vote down vote up
@Override
public ProductPage getPrevPage(ProductType pt, ProductPage currentPage) {
   ProductPage pp = new ProductPage();
   pp.setPageNum(currentPage.getPageNum() - 1);
   pp.setTotalPages(currentPage.getTotalPages());
   pp.setPageSize(currentPage.getPageSize());
   Product p4 = new Product();
   p4.setProductId(PRODUCT_ID_4);
   p4.setProductName(PRODUCT_NAME_4);
   p4.setProductType(pt);
   p4.setProductStructure(PRODUCT_STRUCTURE);
   p4.setTransferStatus(PRODUCT_STATUS);
   pp.setPageProducts(Lists.newArrayList(p4));
   return pp;
}
 
Example #29
Source File: KBP2014ScorerBin.java    From tac-kbp-eal with MIT License 5 votes vote down vote up
private static ImmutableList<KBPScoringObserver<TypeRoleFillerRealis>> getCorpusObservers(
    Parameters params) {
  final List<KBPScoringObserver<TypeRoleFillerRealis>> corpusObservers = Lists.newArrayList();

  if (params.getBoolean("annotationComplete")) {
    corpusObservers.add(ExitOnUnannotatedAnswerKey.create());
  }

  final HTMLErrorRecorder dummyRecorder = NullHTMLErrorRecorder.getInstance();
  final ImmutableList<EAScoringObserver.Outputter> outputters = getOutputters(params);
  corpusObservers.add(EAScoringObserver.standardScorer(dummyRecorder, outputters));

  return ImmutableList.copyOf(corpusObservers);
}
 
Example #30
Source File: SemanticNodeProvider.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected SemanticNode add(String featureName, INode child, SemanticNode last) {
	if (featureName == null)
		return last;
	EClass eClass = this.semanticObject.eClass();
	EStructuralFeature feature = eClass.getEStructuralFeature(featureName);
	if (feature == null)
		return last;
	SemanticNode sem = new SemanticNode(child);
	if (last != null) {
		last.follower = sem;
	}
	if (this.first == null) {
		this.first = sem;
	}
	int id = eClass.getFeatureID(feature);
	if (feature.isMany()) {
		@SuppressWarnings("unchecked")
		List<SemanticNode> nodes = (List<SemanticNode>) childrenByFeatureIDAndIndex[id];
		if (nodes == null)
			childrenByFeatureIDAndIndex[id] = nodes = Lists.<SemanticNode>newArrayList();
		nodes.add(sem);
	} else {
		childrenByFeatureIDAndIndex[id] = sem;
	}
	if (feature instanceof EReference) {
		EReference reference = (EReference) feature;
		if (reference.isContainment()) {
			EObject semanitcChild = getSemanticChild(child);
			if (semanitcChild != null) {
				if (this.childrenBySemanticChild == null)
					this.childrenBySemanticChild = Maps.newHashMap();
				this.childrenBySemanticChild.put(semanitcChild, sem);
			}
		}
	}
	return sem;
}