Search in sources :

Example 41 with Metadata

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Metadata in project core-java by SpineEventEngine.

the class MetadataConverter method toMetadata.

/**
 * Returns the {@link Metadata}, containing the {@link Error} as a byte array.
 *
 * @param error the error to convert
 * @return the metadata containing error
 */
public static Metadata toMetadata(Error error) {
    checkNotNull(error);
    final Metadata metadata = new Metadata();
    metadata.put(KEY, error.toByteArray());
    return metadata;
}
Also used : Metadata(io.grpc.Metadata)

Example 42 with Metadata

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Metadata in project core-java by SpineEventEngine.

the class MetadataConverterShould method return_metadata_containing_error.

// A part of the test.
@SuppressWarnings("ConstantConditions")
@Test
public void return_metadata_containing_error() throws InvalidProtocolBufferException {
    final Error error = Error.getDefaultInstance();
    final Metadata metadata = MetadataConverter.toMetadata(error);
    final byte[] bytes = metadata.get(MetadataConverter.KEY);
    assertEquals(error, Error.parseFrom(bytes));
}
Also used : Metadata(io.grpc.Metadata) Error(io.spine.base.Error) Test(org.junit.Test)

Example 43 with Metadata

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Metadata in project core-java by SpineEventEngine.

the class MetadataConverterShould method return_absent_if_metadata_is_empty.

@Test
public void return_absent_if_metadata_is_empty() {
    final Metadata metadata = new Metadata();
    assertFalse(MetadataConverter.toError(metadata).isPresent());
}
Also used : Metadata(io.grpc.Metadata) Test(org.junit.Test)

Example 44 with Metadata

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Metadata in project core-java by SpineEventEngine.

the class MetadataConverterShould method return_error_extracted_form_metadata.

@Test
public void return_error_extracted_form_metadata() {
    final Error expectedError = Error.getDefaultInstance();
    final Metadata metadata = MetadataConverter.toMetadata(expectedError);
    assertEquals(expectedError, MetadataConverter.toError(metadata).get());
}
Also used : Metadata(io.grpc.Metadata) Error(io.spine.base.Error) Test(org.junit.Test)

Example 45 with Metadata

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Metadata in project core-java by SpineEventEngine.

the class StreamObserversShould method return_absent_if_there_is_no_error_in_metadata.

@Test
public void return_absent_if_there_is_no_error_in_metadata() {
    final Metadata emptyMetadata = new Metadata();
    final Throwable statusRuntimeEx = INVALID_ARGUMENT.asRuntimeException(emptyMetadata);
    assertFalse(StreamObservers.fromStreamError(statusRuntimeEx).isPresent());
}
Also used : Metadata(io.grpc.Metadata) Test(org.junit.Test)

Aggregations

Metadata (io.grpc.Metadata)701 Test (org.junit.Test)559 Status (io.grpc.Status)190 CallOptions (io.grpc.CallOptions)56 ClientStreamTracer (io.grpc.ClientStreamTracer)51 ServerCall (io.grpc.ServerCall)48 PickSubchannelArgs (io.grpc.LoadBalancer.PickSubchannelArgs)44 InOrder (org.mockito.InOrder)41 Subchannel (io.grpc.LoadBalancer.Subchannel)40 ByteArrayInputStream (java.io.ByteArrayInputStream)40 InputStream (java.io.InputStream)38 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)33 IOException (java.io.IOException)32 AtomicReference (java.util.concurrent.atomic.AtomicReference)32 Context (io.grpc.Context)31 MockClientTransportInfo (io.grpc.internal.TestUtils.MockClientTransportInfo)31 InternalMetadata (io.grpc.InternalMetadata)30 MethodDescriptor (io.grpc.MethodDescriptor)30 EquivalentAddressGroup (io.grpc.EquivalentAddressGroup)29 ManagedChannel (io.grpc.ManagedChannel)27