/** Creates an {@code Operation} object for this builder. */ public Operation build() { return new Operation(this); } }
@Test public void testOf() { Operation operation = Operation.of(ID, PRODUCER); assertEquals(ID, operation.getId()); assertEquals(PRODUCER, operation.getProducer()); assertFalse(operation.first()); assertFalse(operation.last()); }
private void compareLogOperation(Operation expected, Operation value) { assertEquals(expected, value); assertEquals(expected.getId(), value.getId()); assertEquals(expected.getProducer(), value.getProducer()); assertEquals(expected.first(), value.first()); assertEquals(expected.last(), value.last()); assertEquals(expected.hashCode(), value.hashCode()); assertEquals(expected.toString(), value.toString()); } }
builder.setOperation(operation.toPb());
builder.setOperation(Operation.fromPb(entryPb.getOperation()));
/** * Returns a {@code Operation} object given the operation and producer identifiers. The * combination of producer and id must be globally unique. */ public static Operation of(String id, String producer) { return newBuilder(id, producer).build(); }
.addLabel("key2", "value2") .setLogName(logId) .setOperation(Operation.of("operationId", "operationProducer")) .setResource(MonitoredResource.newBuilder("cloudsql_database").build()) .build(); assertEquals(ImmutableMap.of("key2", "value2"), entry.getLabels()); assertEquals("cloudsql_database", entry.getResource().getType()); assertEquals(Operation.of("operationId", "operationProducer"), entry.getOperation()); assertEquals(Severity.DEFAULT, entry.getSeverity()); assertNull(entry.getHttpRequest());
builder.setOperation(operation.toPb());
builder.setOperation(Operation.fromPb(entryPb.getOperation()));
static Operation fromPb(LogEntryOperation operationPb) { return newBuilder(operationPb.getId(), operationPb.getProducer()) .setFirst(operationPb.getFirst()) .setLast(operationPb.getLast()) .build(); } }
.clearLabels() .addLabel("key", "value") .setOperation(Operation.of("otherId", "otherProducer")) .setTrace("otherTrace") .setSpanId("otherSpanId") assertEquals(request, logEntry.getHttpRequest()); assertEquals(ImmutableMap.of("key", "value"), logEntry.getLabels()); assertEquals(Operation.of("otherId", "otherProducer"), logEntry.getOperation()); assertEquals("otherTrace", logEntry.getTrace()); assertEquals("otherSpanId", logEntry.getSpanId());
@Test public void testBuilder() { assertEquals(ID, OPERATION.getId()); assertEquals(PRODUCER, OPERATION.getProducer()); assertTrue(OPERATION.first()); assertFalse(OPERATION.last()); }
/** * Returns a {@code Operation} object given the operation and producer identifiers. The * combination of producer and id must be globally unique. */ public static Operation of(String id, String producer) { return newBuilder(id, producer).build(); }
/** Creates an {@code Operation} object for this builder. */ public Operation build() { return new Operation(this); } }
@Test public void testToBuilder() { compareLogOperation(OPERATION, OPERATION.toBuilder().build()); Operation operation = OPERATION .toBuilder() .setId("newId") .setProducer("newProducer") .setFirst(false) .setLast(true) .build(); assertEquals("newId", operation.getId()); assertEquals("newProducer", operation.getProducer()); assertFalse(operation.first()); assertTrue(operation.last()); operation = operation.toBuilder().setId(ID).setProducer(PRODUCER).setFirst(FIRST).setLast(LAST).build(); compareLogOperation(OPERATION, operation); }
static Operation fromPb(LogEntryOperation operationPb) { return newBuilder(operationPb.getId(), operationPb.getProducer()) .setFirst(operationPb.getFirst()) .setLast(operationPb.getLast()) .build(); } }