Java 类com.amazonaws.services.dynamodbv2.document.internal.IteratorSupport 实例源码

项目:outland    文件:DefaultGroupStorage.java   
@Override public Optional<Group> loadByKey(String key) {
  Table table = dynamoDB.getTable(this.groupTableName);

  QuerySpec querySpec = new QuerySpec()
      .withKeyConditionExpression(HASH_KEY + " = :k_app_key")
      .withValueMap(new ValueMap()
          .withString(":k_app_key", key)
      )
      .withMaxResultSize(1)
      .withConsistentRead(true);

  DynamoDbCommand<ItemCollection<QueryOutcome>> cmd = new DynamoDbCommand<>("loadByKey",
      () -> queryTable(table, querySpec),
      () -> {
        throw new RuntimeException("loadByKey");
      },
      dynamodbNamespaceGraphQueryHystrix,
      metrics);

  final ItemCollection<QueryOutcome> items = cmd.execute();
  final IteratorSupport<Item, QueryOutcome> iterator = items.iterator();
  if (iterator.hasNext()) {
    return Optional.of(GroupSupport.toGroup(iterator.next().getString("json")));
  }

  return Optional.empty();
}
项目:SPLGroundControl    文件:MAVLinkMessagesTable.java   
public MAVLinkRecordIterable(IteratorSupport<Item, QueryOutcome> it) {
    this.itemIterator = it;
}
项目:Cheddar    文件:DynamoDocumentStoreTemplateTest.java   
@Test
public void shouldQueryIndex_withAttributeQueryOnHashPartOfCompoundIndex() {
    // Given
    final ItemId itemId = new ItemId(randomId());

    final ItemConfiguration itemConfiguration = new ItemConfiguration(StubWithGlobalSecondaryIndexItem.class,
            tableName);
    itemConfiguration.registerIndexes((Arrays.asList(new CompoundIndexDefinition("gsi", "gsiSupportingValue"))));
    final Collection<ItemConfiguration> itemConfigurations = Arrays.asList(itemConfiguration);
    when(mockDatabaseSchemaHolder.itemConfigurations()).thenReturn(itemConfigurations);

    final Table mockTable = mock(Table.class);
    when(mockDynamoDBClient.getTable(any(String.class))).thenReturn(mockTable);

    final DynamoDocumentStoreTemplate dynamoDocumentStoreTemplate = new DynamoDocumentStoreTemplate(
            mockDatabaseSchemaHolder);
    dynamoDocumentStoreTemplate.initialize(mockAmazonDynamoDbClient);

    final Index mockIndex = mock(Index.class);
    when(mockTable.getIndex(anyString())).thenReturn(mockIndex);

    final ItemCollection<QueryOutcome> mockOutcome = mock(ItemCollection.class);
    when(mockIndex.query(any(QuerySpec.class))).thenReturn(mockOutcome);

    final IteratorSupport<Item, QueryOutcome> mockIterator = mock(IteratorSupport.class);
    final Item mockItem = new Item();
    mockItem.withString(randomString(), randomString());

    when(mockOutcome.iterator()).thenReturn(mockIterator);
    when(mockIterator.hasNext()).thenReturn(true, false);
    when(mockIterator.next()).thenReturn(mockItem);

    // When
    final Collection<StubWithGlobalSecondaryIndexItem> stubWithGlobalSecondaryIndexItemCollection = dynamoDocumentStoreTemplate
            .fetch(new AttributeQuery("gsi", new Condition(Operators.EQUALS, itemId.value())),
                    StubWithGlobalSecondaryIndexItem.class);

    // Then
    assertTrue(stubWithGlobalSecondaryIndexItemCollection.size() == 1);
    final ArgumentCaptor<QuerySpec> querySpecCaptor = ArgumentCaptor.forClass(QuerySpec.class);
    verify(mockIndex).query(querySpecCaptor.capture());
}
项目:Cheddar    文件:DynamoDocumentStoreTemplateTest.java   
@Test
public void shouldQueryIndex_withCompoundAttributeQuery() {
    // Given
    final ItemId itemId = new ItemId(randomId());

    final ItemConfiguration itemConfiguration = new ItemConfiguration(StubWithGlobalSecondaryIndexItem.class,
            tableName);
    itemConfiguration.registerIndexes((Arrays.asList(new CompoundIndexDefinition("gsi", "gsiSupportingValue"))));
    final Collection<ItemConfiguration> itemConfigurations = Arrays.asList(itemConfiguration);
    when(mockDatabaseSchemaHolder.itemConfigurations()).thenReturn(itemConfigurations);

    final Table mockTable = mock(Table.class);
    when(mockDynamoDBClient.getTable(any(String.class))).thenReturn(mockTable);

    final DynamoDocumentStoreTemplate dynamoDocumentStoreTemplate = new DynamoDocumentStoreTemplate(
            mockDatabaseSchemaHolder);
    dynamoDocumentStoreTemplate.initialize(mockAmazonDynamoDbClient);

    final Index mockIndex = mock(Index.class);
    when(mockTable.getIndex(anyString())).thenReturn(mockIndex);

    final ItemCollection<QueryOutcome> mockOutcome = mock(ItemCollection.class);
    when(mockIndex.query(any(QuerySpec.class))).thenReturn(mockOutcome);

    final IteratorSupport<Item, QueryOutcome> mockIterator = mock(IteratorSupport.class);
    final Item mockItem = new Item();
    mockItem.withString(randomString(), randomString());

    when(mockOutcome.iterator()).thenReturn(mockIterator);
    when(mockIterator.hasNext()).thenReturn(true, false);
    when(mockIterator.next()).thenReturn(mockItem);

    // When
    final Collection<StubWithGlobalSecondaryIndexItem> stubWithGlobalSecondaryIndexItemCollection = dynamoDocumentStoreTemplate
            .fetch(new CompoundAttributeQuery("gsi", new Condition(Operators.EQUALS, itemId.value()),
                    "gsiSupportingValue", new Condition(Operators.EQUALS, String.valueOf(randomInt(10)))),
                    StubWithGlobalSecondaryIndexItem.class);

    // Then
    assertTrue(stubWithGlobalSecondaryIndexItemCollection.size() == 1);
    final ArgumentCaptor<QuerySpec> querySpecCaptor = ArgumentCaptor.forClass(QuerySpec.class);
    verify(mockIndex).query(querySpecCaptor.capture());
    assertNotNull(querySpecCaptor.getValue().getRangeKeyCondition());
}
项目:Cheddar    文件:DynamoDocumentStoreTemplateTest.java   
@Test
public void shouldQueryIndex_withACompoundAttributeQueryOnACompoundGSIWithAHashValueTheSameAsThePrimaryKeyDefinition() {
    // Given
    final ItemId itemId = new ItemId(randomId());

    final ItemConfiguration itemConfiguration = new ItemConfiguration(StubWithGlobalSecondaryIndexItem.class,
            tableName, new PrimaryKeyDefinition("gsi"));
    itemConfiguration.registerIndexes((Arrays.asList(new CompoundIndexDefinition("gsi", "gsiSupportingValue"))));
    final Collection<ItemConfiguration> itemConfigurations = Arrays.asList(itemConfiguration);
    when(mockDatabaseSchemaHolder.itemConfigurations()).thenReturn(itemConfigurations);

    final Table mockTable = mock(Table.class);
    when(mockDynamoDBClient.getTable(any(String.class))).thenReturn(mockTable);

    final DynamoDocumentStoreTemplate dynamoDocumentStoreTemplate = new DynamoDocumentStoreTemplate(
            mockDatabaseSchemaHolder);
    dynamoDocumentStoreTemplate.initialize(mockAmazonDynamoDbClient);

    final Index mockIndex = mock(Index.class);
    when(mockTable.getIndex(anyString())).thenReturn(mockIndex);

    final ItemCollection<QueryOutcome> mockOutcome = mock(ItemCollection.class);
    when(mockIndex.query(any(QuerySpec.class))).thenReturn(mockOutcome);

    final IteratorSupport<Item, QueryOutcome> mockIterator = mock(IteratorSupport.class);
    final Item mockItem = new Item();
    mockItem.withString(randomString(), randomString());

    when(mockOutcome.iterator()).thenReturn(mockIterator);
    when(mockIterator.hasNext()).thenReturn(true, false);
    when(mockIterator.next()).thenReturn(mockItem);

    // When
    final Collection<StubWithGlobalSecondaryIndexItem> stubWithGlobalSecondaryIndexItemCollection = dynamoDocumentStoreTemplate
            .fetch(new CompoundAttributeQuery("gsi", new Condition(Operators.EQUALS, itemId.value()),
                    "gsiSupportingValue", new Condition(Operators.EQUALS, String.valueOf(randomInt(10)))),
                    StubWithGlobalSecondaryIndexItem.class);

    // Then
    assertTrue(stubWithGlobalSecondaryIndexItemCollection.size() == 1);
    final ArgumentCaptor<QuerySpec> querySpecCaptor = ArgumentCaptor.forClass(QuerySpec.class);
    verify(mockIndex).query(querySpecCaptor.capture());
    assertNotNull(querySpecCaptor.getValue().getRangeKeyCondition());
}