下面列出了com.google.protobuf.ByteString#copyFromUtf8 ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* create temp Wrapper test need.
*/
@Before
public void createWrapper() {
AccountWrapper ownerWrapper =
new AccountWrapper(
ByteString.copyFromUtf8("owner"),
ByteString.copyFrom(ByteArray.fromHexString(OWNER_ADDRESS)),
AccountType.Normal,
dbManager.getDynamicPropertiesStore().getAssetIssueFee());
AccountWrapper ownerSecondWrapper =
new AccountWrapper(
ByteString.copyFromUtf8("ownerSecond"),
ByteString.copyFrom(ByteArray.fromHexString(OWNER_ADDRESS_SECOND)),
AccountType.Normal,
dbManager.getDynamicPropertiesStore().getAssetIssueFee());
dbManager.getAccountStore().put(ownerWrapper.getAddress().toByteArray(), ownerWrapper);
dbManager.getAccountStore().put(
ownerSecondWrapper.getAddress().toByteArray(), ownerSecondWrapper);
dbManager.getDynamicPropertiesStore().saveLatestBlockHeaderTimestamp(24 * 3600 * 1000);
dbManager.getDynamicPropertiesStore().saveAllowSameTokenName(0);
now = dbManager.getHeadBlockTimeStamp();
startTime = now + 48 * 3600 * 1000;
endTime = now + 72 * 3600 * 1000;
}
@ProcessElement
public void processElement(ProcessContext c) {
InputContent i = c.element();
String jobName = c.getPipelineOptions().getJobName();
ByteString rowkey = ByteString.copyFromUtf8(jobName + "#" + i.expectedDocumentHash);
ByteString value = ByteString.copyFromUtf8(i.text);
Iterable<Mutation> mutations =
ImmutableList.of(Mutation.newBuilder()
.setSetCell(
Mutation.SetCell.newBuilder()
.setFamilyName(IndexerPipelineUtils.DEAD_LETTER_TABLE_ERR_CF)
.setColumnQualifier(ByteString.copyFromUtf8("text"))
.setValue(value)
)
.build());
c.output(KV.of(rowkey, mutations));
}
/**
* create temp Wrapper test need.
*/
@Before
public void createWrapper() {
AccountWrapper accountWrapper =
new AccountWrapper(
ByteString.copyFrom(ByteArray.fromHexString(OWNER_ADDRESS)),
ByteString.copyFromUtf8("owner"),
AccountType.Normal);
dbManager.getAccountStore().put(accountWrapper.getAddress().toByteArray(), accountWrapper);
AccountWrapper witnessWrapper =
new AccountWrapper(
ByteString.copyFrom(ByteArray.fromHexString(WITNESS_ADDRESS)),
ByteString.copyFromUtf8("witness"),
AccountType.Normal);
witnessWrapper.setIsWitness(true);
dbManager.getAccountStore().put(witnessWrapper.getAddress().toByteArray(), witnessWrapper);
}
private void createAssertBeforSameTokenNameActive() {
dbManager.getDynamicPropertiesStore().saveAllowSameTokenName(0);
// address in accountStore and the owner of contract
AccountWrapper accountWrapper =
new AccountWrapper(
ByteString.copyFrom(ByteArray.fromHexString(OWNER_ADDRESS)),
ByteString.copyFromUtf8(OWNER_ADDRESS_ACCOUNT_NAME),
Protocol.AccountType.Normal);
// add asset issue
AssetIssueWrapper assetIssueWrapper = new AssetIssueWrapper(getAssetIssueContract());
dbManager.getAssetIssueStore().put(assetIssueWrapper.createDbKey(), assetIssueWrapper);
dbManager.getAssetIssueV2Store().put(assetIssueWrapper.createDbV2Key(), assetIssueWrapper);
accountWrapper.setAssetIssuedName(assetIssueWrapper.createDbKey());
accountWrapper.setAssetIssuedID(assetIssueWrapper.getId().getBytes());
accountWrapper.addAsset(assetIssueWrapper.createDbKey(), TOTAL_SUPPLY);
accountWrapper.addAssetV2(assetIssueWrapper.createDbV2Key(), TOTAL_SUPPLY);
dbManager.getAccountStore().put(ByteArray.fromHexString(OWNER_ADDRESS), accountWrapper);
}
@Test
public void writeSendsSingleInsertObjectRequestWithoutChecksums() throws Exception {
AsyncWriteChannelOptions options =
AsyncWriteChannelOptions.builder().setGrpcChecksumsEnabled(false).build();
ObjectWriteConditions writeConditions = new ObjectWriteConditions();
GoogleCloudStorageGrpcWriteChannel writeChannel =
newWriteChannel(options, writeConditions, Optional.absent());
ByteString data = ByteString.copyFromUtf8("test data");
writeChannel.initialize();
writeChannel.write(data.asReadOnlyByteBuffer());
writeChannel.close();
InsertObjectRequest expectedInsertRequest =
InsertObjectRequest.newBuilder()
.setUploadId(UPLOAD_ID)
.setChecksummedData(ChecksummedData.newBuilder().setContent(data))
.setFinishWrite(true)
.build();
verify(fakeService, times(1)).startResumableWrite(eq(START_REQUEST), any());
verify(fakeService.insertRequestObserver, times(1)).onNext(expectedInsertRequest);
verify(fakeService.insertRequestObserver, atLeast(1)).onCompleted();
}
@Test
public void writeUsesRequesterPaysProjectIfProvided() throws Exception {
AsyncWriteChannelOptions options = AsyncWriteChannelOptions.builder().build();
ObjectWriteConditions writeConditions = new ObjectWriteConditions();
GoogleCloudStorageGrpcWriteChannel writeChannel =
newWriteChannel(options, writeConditions, Optional.of("project-id"));
ByteString data = ByteString.copyFromUtf8("test data");
writeChannel.initialize();
writeChannel.write(data.asReadOnlyByteBuffer());
writeChannel.close();
StartResumableWriteRequest.Builder expectedRequestBuilder = START_REQUEST.toBuilder();
expectedRequestBuilder.getInsertObjectSpecBuilder().setUserProject("project-id");
verify(fakeService, times(1)).startResumableWrite(eq(expectedRequestBuilder.build()), any());
}
@Test
public void putCreatesFile() throws IOException, InterruptedException {
ByteString blob = ByteString.copyFromUtf8("Hello, World");
Digest blobDigest = DIGEST_UTIL.compute(blob);
blobs.put(blobDigest, blob);
Path path = fileCache.put(blobDigest, false);
assertThat(Files.exists(path)).isTrue();
}
RpcOutputStream(
String commandId,
String responseCookie,
StreamType type,
BlockingStreamObserver<RunResponse> observer) {
this.commandIdBytes = ByteString.copyFromUtf8(commandId);
this.responseCookieBytes = ByteString.copyFromUtf8(responseCookie);
this.type = type;
this.observer = observer;
}
@Test
public void testLastResumeTokenWins() {
Map<Integer, TargetData> targetMap = activeQueries(1, 2);
WatchChangeAggregator aggregator =
createAggregator(targetMap, noOutstandingResponses, noExistingKeys);
WatchTargetChange change1 = new WatchTargetChange(WatchTargetChangeType.Current, asList(1));
aggregator.handleTargetChange(change1);
ByteString resumeToken2 = ByteString.copyFromUtf8("resumeToken2");
WatchTargetChange change2 =
new WatchTargetChange(WatchTargetChangeType.Current, asList(1), resumeToken2);
aggregator.handleTargetChange(change2);
ByteString resumeToken3 = ByteString.copyFromUtf8("resumeToken3");
WatchTargetChange change3 =
new WatchTargetChange(WatchTargetChangeType.Current, asList(2), resumeToken3);
aggregator.handleTargetChange(change3);
RemoteEvent event = aggregator.createRemoteEvent(version(3));
assertEquals(2, event.getTargetChanges().size());
TargetChange mapping1 = targetChange(resumeToken2, true, null, null, null);
assertEquals(mapping1, event.getTargetChanges().get(1));
TargetChange mapping2 = targetChange(resumeToken3, true, null, null, null);
assertEquals(mapping2, event.getTargetChanges().get(2));
}
@Test
public void containsRecordsAccess() throws IOException, InterruptedException {
ByteString contentOne = ByteString.copyFromUtf8("one");
Digest digestOne = DIGEST_UTIL.compute(contentOne);
blobs.put(digestOne, contentOne);
ByteString contentTwo = ByteString.copyFromUtf8("two");
Digest digestTwo = DIGEST_UTIL.compute(contentTwo);
blobs.put(digestTwo, contentTwo);
ByteString contentThree = ByteString.copyFromUtf8("three");
Digest digestThree = DIGEST_UTIL.compute(contentThree);
blobs.put(digestThree, contentThree);
String pathOne = fileCache.put(digestOne, /* isExecutable=*/ false).getFileName().toString();
String pathTwo = fileCache.put(digestTwo, /* isExecutable=*/ false).getFileName().toString();
String pathThree =
fileCache.put(digestThree, /* isExecutable=*/ false).getFileName().toString();
fileCache.decrementReferences(
ImmutableList.of(pathOne, pathTwo, pathThree), ImmutableList.of());
/* three -> two -> one */
assertThat(storage.get(pathOne).after).isEqualTo(storage.get(pathTwo));
assertThat(storage.get(pathTwo).after).isEqualTo(storage.get(pathThree));
/* one -> three -> two */
assertThat(fileCache.findMissingBlobs(ImmutableList.of(digestOne))).isEmpty();
assertThat(storage.get(pathTwo).after).isEqualTo(storage.get(pathThree));
assertThat(storage.get(pathThree).after).isEqualTo(storage.get(pathOne));
}
/** Helper function to store state data. */
private void storeGameData(
String address, GameData gameData, String stateEntry, Context context)
throws InternalError, InvalidTransactionException {
String gameDataCsv = String.format("%s,%s,%s,%s,%s",
gameData.gameName, gameData.board, gameData.state, gameData.playerOne, gameData.playerTwo);
if (stateEntry.length() == 0) {
stateEntry = gameDataCsv;
} else {
ArrayList<String> dataList = new ArrayList<>(Arrays.asList(stateEntry.split("\\|")));
for (int i = 0; i <= dataList.size(); i++) {
if (i == dataList.size()
|| dataList.get(i).regionMatches(0, gameData.gameName, 0, gameData.gameName.length())) {
dataList.set(i, gameDataCsv);
break;
}
}
stateEntry = StringUtils.join(dataList, "|");
}
ByteString csvByteString = ByteString.copyFromUtf8(stateEntry);
Map.Entry<String, ByteString> entry = new AbstractMap.SimpleEntry<>(address, csvByteString);
Collection<Map.Entry<String, ByteString>> addressValues = Collections.singletonList(entry);
Collection<String> addresses = context.setState(addressValues);
if (addresses.size() < 1) {
throw new InternalError("State Error");
}
}
@Test
public void writePutsIntoBlobStore() throws IOException, InterruptedException {
ByteString helloWorld = ByteString.copyFromUtf8("Hello, World!");
Digest digest = DIGEST_UTIL.compute(helloWorld);
String uuid = UUID.randomUUID().toString();
String resourceName = createBlobUploadResourceName(uuid, digest);
Channel channel = InProcessChannelBuilder.forName(fakeServerName).directExecutor().build();
ClientCall<WriteRequest, WriteResponse> call =
channel.newCall(ByteStreamGrpc.getWriteMethod(), CallOptions.DEFAULT);
ClientCall.Listener<WriteResponse> callListener =
new ClientCall.Listener<WriteResponse>() {
boolean complete = false;
boolean callHalfClosed = false;
@Override
public void onReady() {
while (call.isReady()) {
if (complete) {
if (!callHalfClosed) {
call.halfClose();
callHalfClosed = true;
}
return;
}
call.sendMessage(
WriteRequest.newBuilder()
.setResourceName(resourceName)
.setData(helloWorld)
.setFinishWrite(true)
.build());
complete = true;
}
}
};
call.start(callListener, new Metadata());
call.request(1);
verify(simpleBlobStore, times(1))
.put(eq(digest.getHash()), eq(digest.getSizeBytes()), any(InputStream.class));
}
@Test
public void testWrongLength() {
ByteString out1 = ByteString.copyFromUtf8("output query 1");
GroupBySpec.Builder gspec1 = GroupBySpec.newBuilder().addGroupBy("g1").addGroupBy("g2");
gspec1.addAggregateBuilder().setName("a1").setHow(Agg.SUM);
gspec1.addAggregateBuilder().setName("a2").setHow(Agg.COUNT);
gspec1.addAggregateBuilder().setName("a3").setHow(Agg.MIN);
gspec1.addAggregateBuilder().setName("a4").setHow(Agg.MAX);
EmitSpec emitspec1 = EmitSpec.newBuilder().setOutputId(out1).setGroupBySpec(gspec1).build();
EmitGrouped emit1 = new EmitGrouped(emitspec1, gspec1.build());
List<Object[]> tuples1 = Lists.<Object[]>newArrayList(
new Object[] { "hello", "goodbye", 1, 2, 1, }
);
emit1.emit(tuples1);
AgentInfo myInfo = PTAgent.getAgentInfo();
long timestamp = 100;
QueryResults results = emit1.getResults(myInfo, timestamp);
assertEquals(emitspec1, results.getEmit());
assertEquals(myInfo, results.getAgent());
assertEquals(timestamp, results.getTimestamp());
assertEquals(0, results.getTupleCount());
assertEquals(0, results.getGroupCount());
List<Object[]> tuples2 = Lists.<Object[]>newArrayList(
new Object[] { "hello", "goodbye", 1, 2, 1, 3, 5 }
);
emit1.emit(tuples2);
assertEquals(emitspec1, results.getEmit());
assertEquals(myInfo, results.getAgent());
assertEquals(timestamp, results.getTimestamp());
assertEquals(0, results.getTupleCount());
assertEquals(0, results.getGroupCount());
}
public FakeBatchTransactionId(String id) {
super("", ByteString.copyFromUtf8(""), Timestamp.MIN_VALUE);
this.id = id;
}
private int computeSize(FieldInfo fieldInfo, Object value) throws IOException {
FieldType fieldType = fieldInfo.getFieldType();
int size = 0;
if (value instanceof List) {
// if list
size = CodedConstant.computeListSize(fieldInfo.getOrder(), (List) value, fieldInfo.getFieldType(), true, null);
return size;
}
int order = fieldInfo.getOrder();
switch (fieldType) {
case DOUBLE:
size = CodedOutputStream.computeDoubleSize(order, (Double) value);
break;
case BYTES:
ByteString bytes = ByteString.copyFrom((byte[]) value);
size = CodedOutputStream.computeBytesSize(order, bytes);
break;
case STRING:
ByteString string = ByteString.copyFromUtf8(value.toString());
size = CodedOutputStream.computeBytesSize(order, string);
break;
case BOOL:
size = CodedOutputStream.computeBoolSize(order, (Boolean) value);
break;
case FIXED32:
size = CodedOutputStream.computeFixed32Size(order, (Integer) value);
break;
case SFIXED32:
size = CodedOutputStream.computeSFixed32Size(order, (Integer) value);
break;
case SINT32:
size = CodedOutputStream.computeSInt32Size(order, (Integer) value);
break;
case INT32:
size = CodedOutputStream.computeInt32Size(order, (Integer) value);
break;
case UINT32:
size = CodedOutputStream.computeUInt32Size(order, (Integer) value);
break;
case FIXED64:
size = CodedOutputStream.computeFixed64Size(order, (Long) value);
break;
case SFIXED64:
size = CodedOutputStream.computeSFixed64Size(order, (Long) value);
break;
case SINT64:
size = CodedOutputStream.computeSInt64Size(order, (Long) value);
break;
case INT64:
size = CodedOutputStream.computeInt64Size(order, (Long) value);
break;
case UINT64:
size = CodedOutputStream.computeUInt64Size(order, (Long) value);
break;
case ENUM:
int i;
i = getEnumValue(value);
size = CodedOutputStream.computeEnumSize(order, i);
break;
case FLOAT:
size = CodedOutputStream.computeFloatSize(order, (Float) value);
break;
case OBJECT:
Class c = value.getClass();
ReflectiveCodec codec = new ReflectiveCodec(c);
int objectSize = codec.size(value);
size = size + CodedOutputStream.computeRawVarint32Size(objectSize);
size = size + CodedOutputStream.computeTagSize(order);
size += objectSize;
break;
default:
throw new IOException("Unknown field type on field '" + fieldInfo.getField().getName() + "'");
}
return size;
}
/**
* constructor.
*/
@Test(enabled = true, description = "Trigger transferTokenwithSameName")
public void deploy02TransferTokenContract() {
Account info;
AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(dev001Address,
blockingStubFull);
info = PublicMethed.queryAccount(dev001Address, blockingStubFull);
Long beforeBalance = info.getBalance();
Long beforeCpuUsed = resourceInfo.getCpuUsed();
Long beforeNetUsed = resourceInfo.getNetUsed();
Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed();
Long beforeAssetIssueDevAddress = PublicMethed
.getAssetIssueValue(dev001Address, assetAccountId,
blockingStubFull);
Long beforeAssetIssueUserAddress = PublicMethed
.getAssetIssueValue(user001Address, assetAccountId,
blockingStubFull);
Long beforeAssetIssueContractAddress = PublicMethed
.getAssetIssueValue(transferTokenContractAddress,
assetAccountId,
blockingStubFull);
Long beforeBalanceContractAddress = PublicMethed.queryAccount(transferTokenContractAddress,
blockingStubFull).getBalance();
Long beforeUserBalance = PublicMethed.queryAccount(user001Address, blockingStubFull)
.getBalance();
logger.info("beforeBalance:" + beforeBalance);
logger.info("beforeCpuUsed:" + beforeCpuUsed);
logger.info("beforeNetUsed:" + beforeNetUsed);
logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed);
logger.info("beforeAssetIssueCount:" + beforeAssetIssueContractAddress);
logger.info("beforeAssetIssueDevAddress:" + beforeAssetIssueDevAddress);
logger.info("beforeAssetIssueUserAddress:" + beforeAssetIssueUserAddress);
logger.info("beforeBalanceContractAddress:" + beforeBalanceContractAddress);
logger.info("beforeUserBalance:" + beforeUserBalance);
// user trigger A to transfer token to B
ByteString assetAccountDev = PublicMethed
.queryAccount(dev001Address, blockingStubFull).getAssetIssuedID();
ByteString fakeTokenId = ByteString
.copyFromUtf8(Long.toString(Long.valueOf(assetAccountDev.toStringUtf8()) + 100));
String param = "\"" + fakeTokenId.toStringUtf8() + "\",\"1\"";
final String triggerTxid = PublicMethed.triggerContract(transferTokenContractAddress,
"transferTokenWithSameName(grcToken,uint256)",
param, false, 0, 1000000000L, "0",
0, dev001Address, dev001Key,
blockingStubFull);
PublicMethed.waitProduceNextBlock(blockingStubFull);
PublicMethed.waitProduceNextBlock(blockingStubFull);
Account infoafter = PublicMethed.queryAccount(dev001Address, blockingStubFull);
AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(dev001Address,
blockingStubFull);
Long afterBalance = infoafter.getBalance();
Long afterCpuUsed = resourceInfoafter.getCpuUsed();
Long afterAssetIssueDevAddress = PublicMethed
.getAssetIssueValue(dev001Address, assetAccountId,
blockingStubFull);
Long afterNetUsed = resourceInfoafter.getNetUsed();
Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed();
Long afterAssetIssueContractAddress = PublicMethed
.getAssetIssueValue(transferTokenContractAddress,
assetAccountId,
blockingStubFull);
Long afterAssetIssueUserAddress = PublicMethed
.getAssetIssueValue(user001Address, assetAccountId,
blockingStubFull);
Long afterBalanceContractAddress = PublicMethed.queryAccount(transferTokenContractAddress,
blockingStubFull).getBalance();
Long afterUserBalance = PublicMethed.queryAccount(user001Address, blockingStubFull)
.getBalance();
logger.info("afterBalance:" + afterBalance);
logger.info("afterCpuUsed:" + afterCpuUsed);
logger.info("afterNetUsed:" + afterNetUsed);
logger.info("afterFreeNetUsed:" + afterFreeNetUsed);
logger.info("afterAssetIssueCount:" + afterAssetIssueDevAddress);
logger.info("afterAssetIssueDevAddress:" + afterAssetIssueContractAddress);
logger.info("afterAssetIssueUserAddress:" + afterAssetIssueUserAddress);
logger.info("afterBalanceContractAddress:" + afterBalanceContractAddress);
logger.info("afterUserBalance:" + afterUserBalance);
Optional<TransactionInfo> infoById = PublicMethed
.getTransactionInfoById(triggerTxid, blockingStubFull);
Assert.assertTrue(infoById.get().getResultValue() == 0);
Assert.assertTrue(afterAssetIssueUserAddress == beforeAssetIssueUserAddress);
Assert.assertEquals(afterBalanceContractAddress, beforeBalanceContractAddress);
Assert.assertEquals(afterUserBalance, beforeUserBalance);
Assert.assertTrue(afterAssetIssueContractAddress == beforeAssetIssueContractAddress);
PublicMethed.unFreezeBalance(dev001Address, dev001Key, 1,
null, blockingStubFull);
PublicMethed.unFreezeBalance(user001Address, user001Key, 1,
null, blockingStubFull);
}
/**
* The {@link BigQueryToTFRecord#buildFeature} method takes in an individual field and type
* corresponding to a column value from a SchemaAndRecord Object returned from a BigQueryIO.read()
* step. The method builds a TensorFlow Feature based on the type of the object- ie: STRING, TIME,
* INTEGER etc..
*/
private static Feature buildFeature(Object field, String type) {
Feature.Builder feature = Feature.newBuilder();
ByteString byteString;
switch (type) {
case "STRING":
case "TIME":
case "DATE":
if (field instanceof GenericData.Array) {
buildFeatureFromIterator(String.class, field, feature);
} else {
byteString = ByteString.copyFromUtf8(field.toString());
feature.getBytesListBuilder().addValue(byteString);
}
break;
case "BYTES":
byteString = ByteString.copyFrom((byte[]) field);
feature.getBytesListBuilder().addValue(byteString);
break;
case "INTEGER":
case "INT64":
case "TIMESTAMP":
if (field instanceof GenericData.Array) {
buildFeatureFromIterator(Long.class, field, feature);
} else {
feature.getInt64ListBuilder().addValue((long) field);
}
break;
case "FLOAT":
case "FLOAT64":
if (field instanceof GenericData.Array) {
buildFeatureFromIterator(double.class, field, feature);
} else {
feature.getFloatListBuilder().addValue((float) (double) field);
}
break;
case "BOOLEAN":
case "BOOL":
if (field instanceof GenericData.Array) {
buildFeatureFromIterator(boolean.class, field, feature);
} else {
int boolAsInt = (boolean) field ? 1 : 0;
feature.getInt64ListBuilder().addValue(boolAsInt);
}
break;
default:
throw new RuntimeException("Unsupported type: " + type);
}
return feature.build();
}
@Test
public void testEmitGroupedSimple() {
int groupCount = 2;
int aggCount = 4;
ByteString out1 = ByteString.copyFromUtf8("output query 1");
GroupBySpec.Builder gspec1 = GroupBySpec.newBuilder().addGroupBy("g1").addGroupBy("g2");
gspec1.addAggregateBuilder().setName("a1").setHow(Agg.SUM);
gspec1.addAggregateBuilder().setName("a2").setHow(Agg.COUNT);
gspec1.addAggregateBuilder().setName("a3").setHow(Agg.MIN);
gspec1.addAggregateBuilder().setName("a4").setHow(Agg.MAX);
EmitSpec emitspec1 = EmitSpec.newBuilder().setOutputId(out1).setGroupBySpec(gspec1).build();
EmitGrouped emit1 = new EmitGrouped(emitspec1, gspec1.build());
List<Object[]> tuples1 = Lists.<Object[]>newArrayList(
new Object[] { "hello", "goodbye", 1, 2, 3, 4 }
);
emit1.emit(tuples1);
AgentInfo myInfo = PTAgent.getAgentInfo();
long timestamp = 100;
QueryResults results = emit1.getResults(myInfo, timestamp);
assertEquals(emitspec1, results.getEmit());
assertEquals(myInfo, results.getAgent());
assertEquals(timestamp, results.getTimestamp());
assertEquals(0, results.getTupleCount());
assertEquals(1, results.getGroupCount());
ResultsGroup.Builder expect = ResultsGroup.newBuilder();
expect.addGroupBy("hello").addGroupBy("goodbye").addAggregation(1).addAggregation(1).addAggregation(3).addAggregation(4);
assertEquals(expect.build(), results.getGroup(0));
QueryResults results2 = emit1.getResults(myInfo, timestamp);
assertEquals(emitspec1, results2.getEmit());
assertEquals(myInfo, results2.getAgent());
assertEquals(timestamp, results2.getTimestamp());
assertEquals(0, results2.getTupleCount());
assertEquals(0, results2.getGroupCount());
}
private List<AccountWrapper> getAccountList() {
final List<AccountWrapper> accountWrapperList = Lists.newArrayList();
final AccountWrapper accountGSC =
new AccountWrapper(
ByteString.copyFrom("00000000001".getBytes()),
ByteString.copyFromUtf8("GSC"),
AccountType.Normal);
final AccountWrapper accountMarcus =
new AccountWrapper(
ByteString.copyFrom("00000000002".getBytes()),
ByteString.copyFromUtf8("Marcus"),
AccountType.Normal);
final AccountWrapper accountOlivier =
new AccountWrapper(
ByteString.copyFrom("00000000003".getBytes()),
ByteString.copyFromUtf8("Olivier"),
AccountType.Normal);
final AccountWrapper accountSasaXie =
new AccountWrapper(
ByteString.copyFrom("00000000004".getBytes()),
ByteString.copyFromUtf8("SasaXie"),
AccountType.Normal);
final AccountWrapper accountVivider =
new AccountWrapper(
ByteString.copyFrom("00000000005".getBytes()),
ByteString.copyFromUtf8("Vivider"),
AccountType.Normal);
// accountGSC addVotes
accountGSC.addVotes(accountMarcus.getAddress(), 100);
accountGSC.addVotes(accountOlivier.getAddress(), 100);
accountGSC.addVotes(accountSasaXie.getAddress(), 100);
accountGSC.addVotes(accountVivider.getAddress(), 100);
// accountMarcus addVotes
accountMarcus.addVotes(accountGSC.getAddress(), 100);
accountMarcus.addVotes(accountOlivier.getAddress(), 100);
accountMarcus.addVotes(accountSasaXie.getAddress(), 100);
accountMarcus.addVotes(ByteString.copyFrom("00000000006".getBytes()), 100);
accountMarcus.addVotes(ByteString.copyFrom("00000000007".getBytes()), 100);
// accountOlivier addVotes
accountOlivier.addVotes(accountGSC.getAddress(), 100);
accountOlivier.addVotes(accountMarcus.getAddress(), 100);
accountOlivier.addVotes(accountSasaXie.getAddress(), 100);
accountOlivier.addVotes(accountVivider.getAddress(), 100);
// accountSasaXie addVotes
// accountVivider addVotes
accountWrapperList.add(accountGSC);
accountWrapperList.add(accountMarcus);
accountWrapperList.add(accountOlivier);
accountWrapperList.add(accountSasaXie);
accountWrapperList.add(accountVivider);
return accountWrapperList;
}
private static HasAllMapValues hasAllMapValues() {
Value value = Value.newBuilder().setStringValue("test").build();
ByteString byteString = ByteString.copyFromUtf8("test");
Any any = Any
.newBuilder()
.setTypeUrl("type.googleapis.com/google.protobuf.Value")
.setValue(value.toByteString())
.build();
return HasAllMapValues
.newBuilder()
.putDoubleMap("double", 1.5d)
.putFloatMap("float", 2.5f)
.putInt32Map("int32", 1)
.putInt64Map("int64", 2)
.putUint32Map("uint32", 3)
.putUint64Map("uint64", 4)
.putSint32Map("sint32", 5)
.putSint64Map("sint64", 6)
.putFixed32Map("fixed32", 7)
.putFixed64Map("fixed64", 8)
.putSfixed32Map("sfixed32", 9)
.putSfixed64Map("sfixed64", 10)
.putBoolMap("bool", true)
.putStringMap("string", "test")
.putBytesMap("bytes", byteString)
.putAnyMap("any", any)
.putDurationMap("duration", Duration.newBuilder().setSeconds(30).build())
.putFieldMaskMap("field_mask", FieldMask.newBuilder().addPaths("path_one").addPaths("path_two").build())
.putListValueMap("list_value", ListValue.newBuilder().addValues(value).build())
.putNullValueMap("null_value", NullValue.NULL_VALUE)
.putStructMap("struct", Struct.newBuilder().putFields("field", value).build())
.putTimestampMap("timestamp", Timestamp.newBuilder().setSeconds(946684800).build())
.putValueMap("value", value)
.putDoubleWrapperMap("double_wrapper", DoubleValue.newBuilder().setValue(3.5d).build())
.putFloatWrapperMap("float_wrapper", FloatValue.newBuilder().setValue(4.5f).build())
.putInt32WrapperMap("int32_wrapper", Int32Value.newBuilder().setValue(11).build())
.putInt64WrapperMap("int64_wrapper", Int64Value.newBuilder().setValue(12).build())
.putUint32WrapperMap("uint32_wrapper", UInt32Value.newBuilder().setValue(13).build())
.putUint64WrapperMap("uint64_wrapper", UInt64Value.newBuilder().setValue(14).build())
.putBoolWrapperMap("bool_wrapper", BoolValue.newBuilder().setValue(true).build())
.putStringWrapperMap("string_wrapper", StringValue.newBuilder().setValue("test").build())
.putBytesWrapperMap("bytes_wrapper", BytesValue.newBuilder().setValue(byteString).build())
.putEnumMap("enum", EnumProto3.FIRST)
.putProto2MessageMap("proto2", AllFields.newBuilder().setString("proto2").build())
.putProto3MessageMap("proto3", AllFieldsProto3.newBuilder().setString("proto3").build())
.build();
}