本文整理了Java中com.google.protobuf.Timestamp.newBuilder()
方法的一些代码示例,展示了Timestamp.newBuilder()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Timestamp.newBuilder()
方法的具体详情如下:
包路径:com.google.protobuf.Timestamp
类名称:Timestamp
方法名:newBuilder
暂无
代码示例来源:origin: com.google.protobuf/protobuf-java
@java.lang.Override
public Builder newBuilderForType() { return newBuilder(); }
public static Builder newBuilder() {
代码示例来源:origin: googleapis/google-cloud-java
/**
* Returns a {@code com.google.protobuf.Timestamp} initialized to the same point in time as {@code
* this}.
*/
public com.google.protobuf.Timestamp toProto() {
return com.google.protobuf.Timestamp.newBuilder().setSeconds(seconds).setNanos(nanos).build();
}
代码示例来源:origin: googleapis/google-cloud-java
private static Timestamp timestampFromMillis(Long millis) {
Timestamp.Builder tsBuilder = Timestamp.newBuilder();
tsBuilder.setSeconds(millis / MILLIS_PER_SECOND);
tsBuilder.setNanos((int) (millis % MILLIS_PER_SECOND * NANOS_PER_MILLISECOND));
return tsBuilder.build();
}
代码示例来源:origin: googleapis/google-cloud-java
/**
*
*
* <pre>
* The timestamp indicating the time the event occurred.
* </pre>
*
* <code>.google.protobuf.Timestamp time = 1;</code>
*/
public Builder mergeTime(com.google.protobuf.Timestamp value) {
if (timeBuilder_ == null) {
if (time_ != null) {
time_ = com.google.protobuf.Timestamp.newBuilder(time_).mergeFrom(value).buildPartial();
} else {
time_ = value;
}
onChanged();
} else {
timeBuilder_.mergeFrom(value);
}
return this;
}
/**
代码示例来源:origin: googleapis/google-cloud-java
private Timestamp updateTime() {
return Timestamp.newBuilder().setSeconds(++documentCount).build();
}
代码示例来源:origin: googleapis/google-cloud-java
/** <code>.google.protobuf.Timestamp read_time = 3;</code> */
public Builder mergeReadTime(com.google.protobuf.Timestamp value) {
if (readTimeBuilder_ == null) {
if (readTime_ != null) {
readTime_ =
com.google.protobuf.Timestamp.newBuilder(readTime_).mergeFrom(value).buildPartial();
} else {
readTime_ = value;
}
onChanged();
} else {
readTimeBuilder_.mergeFrom(value);
}
return this;
}
/** <code>.google.protobuf.Timestamp read_time = 3;</code> */
代码示例来源:origin: googleapis/google-cloud-java
@Test
@SuppressWarnings("all")
public void scheduleTransferRunsExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockDataTransferService.addException(exception);
try {
TransferConfigName parent = ProjectTransferConfigName.of("[PROJECT]", "[TRANSFER_CONFIG]");
Timestamp startTime = Timestamp.newBuilder().build();
Timestamp endTime = Timestamp.newBuilder().build();
client.scheduleTransferRuns(parent, startTime, endTime);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception
}
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void fromProto() {
com.google.protobuf.Timestamp proto =
com.google.protobuf.Timestamp.newBuilder().setSeconds(1234).setNanos(567).build();
Timestamp timestamp = Timestamp.fromProto(proto);
assertThat(timestamp.getSeconds()).isEqualTo(1234);
assertThat(timestamp.getNanos()).isEqualTo(567);
}
代码示例来源:origin: pinterest/secor
@Test
public void testExtractPathTimestampMillis() throws Exception {
Map<String, String> classPerTopic = new HashMap<String, String>();
System.out.println(TimestampedMessages.UnitTestTimestamp1.class.getName());
classPerTopic.put("test", TimestampedMessages.UnitTestTimestamp1.class.getName());
Mockito.when(mConfig.getMessageTimestampName()).thenReturn("timestamp");
Mockito.when(mConfig.getProtobufMessageClassPerTopic()).thenReturn(classPerTopic);
ProtobufMessageParser parser = new ProtobufMessageParser(mConfig);
Timestamp timestamp = Timestamp.newBuilder().setSeconds(1405970352l)
.setNanos(0).build();
TimestampedMessages.UnitTestTimestamp1 message = TimestampedMessages.UnitTestTimestamp1.newBuilder().setTimestamp(timestamp).build();
assertEquals(1405970352000l,
parser.extractTimestampMillis(new Message("test", 0, 0, null, message.toByteArray(), timestamp.getSeconds())));
Timestamp timestampWithNano = Timestamp.newBuilder().setSeconds(1405970352l)
.setNanos(123000000).build();
message = TimestampedMessages.UnitTestTimestamp1.newBuilder().setTimestamp(timestampWithNano).build();
assertEquals(1405970352123l,
parser.extractTimestampMillis(new Message("test", 0, 0, null, message.toByteArray(), timestamp.getSeconds())));
}
代码示例来源:origin: googleapis/google-cloud-java
private Value timestampValue(long seconds, int nanos) {
return Value.newBuilder()
.setTimestampValue(Timestamp.newBuilder().setSeconds(seconds).setNanos(nanos).build())
.build();
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
@SuppressWarnings("all")
public void cancelLeaseExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockCloudTasks.addException(exception);
try {
TaskName name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]");
Timestamp scheduleTime = Timestamp.newBuilder().build();
client.cancelLease(name, scheduleTime);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception
}
}
代码示例来源:origin: googleapis/google-cloud-java
public static Answer<BatchGetDocumentsResponse> getAllResponse(
final Map<String, Value>... fields) {
BatchGetDocumentsResponse[] responses = new BatchGetDocumentsResponse[fields.length];
for (int i = 0; i < fields.length; ++i) {
String name = DOCUMENT_NAME;
if (fields.length > 1) {
name += i + 1;
}
BatchGetDocumentsResponse.Builder response = BatchGetDocumentsResponse.newBuilder();
response
.getFoundBuilder()
.setCreateTime(com.google.protobuf.Timestamp.newBuilder().setSeconds(1).setNanos(2));
response
.getFoundBuilder()
.setUpdateTime(com.google.protobuf.Timestamp.newBuilder().setSeconds(3).setNanos(4));
response.setReadTime(com.google.protobuf.Timestamp.newBuilder().setSeconds(5).setNanos(6));
response.getFoundBuilder().setName(name).putAllFields(fields[i]);
responses[i] = response.build();
}
return streamingResponse(responses);
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
@SuppressWarnings("all")
public void acknowledgeTaskExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockCloudTasks.addException(exception);
try {
TaskName name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]");
Timestamp scheduleTime = Timestamp.newBuilder().build();
client.acknowledgeTask(name, scheduleTime);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception
}
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
@SuppressWarnings("all")
public void setFindingStateExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockSecurityCenter.addException(exception);
try {
FindingName name = FindingName.of("[ORGANIZATION]", "[SOURCE]", "[FINDING]");
Finding.State state = Finding.State.STATE_UNSPECIFIED;
Timestamp startTime = Timestamp.newBuilder().build();
client.setFindingState(name, state, startTime);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception
}
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void notFound() throws Exception {
final BatchGetDocumentsResponse.Builder getDocumentResponse =
BatchGetDocumentsResponse.newBuilder();
getDocumentResponse.setMissing(DOCUMENT_NAME);
getDocumentResponse.setReadTime(
com.google.protobuf.Timestamp.newBuilder().setSeconds(5).setNanos(6));
doAnswer(streamingResponse(getDocumentResponse.build()))
.when(firestoreMock)
.streamRequest(
getAllCapture.capture(),
streamObserverCapture.capture(),
Matchers.<ServerStreamingCallable>any());
DocumentSnapshot snapshot = documentReference.get().get();
assertEquals(documentReference, snapshot.getReference());
assertFalse(snapshot.exists());
assertEquals(snapshot.getReadTime(), Timestamp.ofTimeSecondsAndNanos(5, 6));
assertNull(snapshot.getData());
}
代码示例来源:origin: googleapis/google-cloud-java
public static Answer<RunQueryResponse> queryResponse(String... documentNames) {
RunQueryResponse[] responses = new RunQueryResponse[documentNames.length];
for (int i = 0; i < documentNames.length; ++i) {
final RunQueryResponse.Builder runQueryResponse = RunQueryResponse.newBuilder();
runQueryResponse.setDocument(
Document.newBuilder().setName(documentNames[i]).putAllFields(SINGLE_FIELD_PROTO));
runQueryResponse.setReadTime(
com.google.protobuf.Timestamp.newBuilder().setSeconds(1).setNanos(2));
responses[i] = runQueryResponse.build();
}
return streamingResponse(responses);
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
@SuppressWarnings("all")
public void renewLeaseExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockCloudTasks.addException(exception);
try {
TaskName name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]");
Timestamp scheduleTime = Timestamp.newBuilder().build();
Duration leaseDuration = Duration.newBuilder().build();
client.renewLease(name, scheduleTime, leaseDuration);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception
}
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
@SuppressWarnings("all")
public void scheduleTransferRunsTest() {
ScheduleTransferRunsResponse expectedResponse =
ScheduleTransferRunsResponse.newBuilder().build();
mockDataTransferService.addResponse(expectedResponse);
TransferConfigName parent = ProjectTransferConfigName.of("[PROJECT]", "[TRANSFER_CONFIG]");
Timestamp startTime = Timestamp.newBuilder().build();
Timestamp endTime = Timestamp.newBuilder().build();
ScheduleTransferRunsResponse actualResponse =
client.scheduleTransferRuns(parent, startTime, endTime);
Assert.assertEquals(expectedResponse, actualResponse);
List<GeneratedMessageV3> actualRequests = mockDataTransferService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ScheduleTransferRunsRequest actualRequest = (ScheduleTransferRunsRequest) actualRequests.get(0);
Assert.assertEquals(parent, TransferConfigNames.parse(actualRequest.getParent()));
Assert.assertEquals(startTime, actualRequest.getStartTime());
Assert.assertEquals(endTime, actualRequest.getEndTime());
Assert.assertTrue(
channelProvider.isHeaderSent(
ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
@SuppressWarnings("all")
public void acknowledgeTaskTest() {
Empty expectedResponse = Empty.newBuilder().build();
mockCloudTasks.addResponse(expectedResponse);
TaskName name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]");
Timestamp scheduleTime = Timestamp.newBuilder().build();
client.acknowledgeTask(name, scheduleTime);
List<GeneratedMessageV3> actualRequests = mockCloudTasks.getRequests();
Assert.assertEquals(1, actualRequests.size());
AcknowledgeTaskRequest actualRequest = (AcknowledgeTaskRequest) actualRequests.get(0);
Assert.assertEquals(name, TaskName.parse(actualRequest.getName()));
Assert.assertEquals(scheduleTime, actualRequest.getScheduleTime());
Assert.assertTrue(
channelProvider.isHeaderSent(
ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
@SuppressWarnings("all")
public void cancelLeaseTest() {
TaskName name2 = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]");
Task expectedResponse = Task.newBuilder().setName(name2.toString()).build();
mockCloudTasks.addResponse(expectedResponse);
TaskName name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]");
Timestamp scheduleTime = Timestamp.newBuilder().build();
Task actualResponse = client.cancelLease(name, scheduleTime);
Assert.assertEquals(expectedResponse, actualResponse);
List<GeneratedMessageV3> actualRequests = mockCloudTasks.getRequests();
Assert.assertEquals(1, actualRequests.size());
CancelLeaseRequest actualRequest = (CancelLeaseRequest) actualRequests.get(0);
Assert.assertEquals(name, TaskName.parse(actualRequest.getName()));
Assert.assertEquals(scheduleTime, actualRequest.getScheduleTime());
Assert.assertTrue(
channelProvider.isHeaderSent(
ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
内容来源于网络,如有侵权,请联系作者删除!