Search in sources :

Example 1 with Schema

use of com.google.pubsub.v1.Schema in project divolte-collector by divolte.

the class GoogleCloudPubSubFlusherTest method testMessageBatchSentToPublisher.

@Test
public void testMessageBatchSentToPublisher() {
    final Publisher publisher = mockPublisher.orElseThrow(IllegalStateException::new);
    // Process a bunch of messages.
    final DivolteSchema schema = new DivolteSchema(MINIMAL_SCHEMA, Optional.empty());
    final GoogleCloudPubSubFlusher flusher = new GoogleCloudPubSubFlusher(publisher, schema);
    final Queue<Item<AvroRecordBuffer>> items = Stream.generate(this::generateMessage).limit(10).map(this::itemFromAvroRecordBuffer).collect(Collectors.toCollection(() -> new ArrayBlockingQueue<>(10)));
    flusher.process(items);
    // Check the messages were all forwarded to the publisher.
    verify(publisher, times(10)).publish(any(PubsubMessage.class));
    verifyNoMoreInteractions(publisher);
}
Also used : Item(io.divolte.server.processing.Item) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) Publisher(com.google.cloud.pubsub.v1.Publisher) PubsubMessage(com.google.pubsub.v1.PubsubMessage) DivolteSchema(io.divolte.server.DivolteSchema) Test(org.junit.Test)

Example 2 with Schema

use of com.google.pubsub.v1.Schema in project divolte-collector by divolte.

the class GoogleCloudPubSubFlusherTest method testMessagesHaveSchemaFingerprint.

@Test
public void testMessagesHaveSchemaFingerprint() {
    processSingleMessage();
    // Reminder: fingerprint is the SHA-256 hash of the normalized schema,
    // base-64 encoded using the URL-safe encoding,
    // with trailing padding stripped.
    final String expectedFingerPrint = BaseEncoding.base64Url().encode(Hashing.sha256().hashString(SchemaNormalization.toParsingForm(MINIMAL_SCHEMA), StandardCharsets.UTF_8).asBytes()).replace("=", "");
    final PubsubMessage deliveredMessage = getFirstPublishedMessage();
    assertEquals(expectedFingerPrint, deliveredMessage.getAttributesOrThrow("schemaFingerprint"));
}
Also used : ByteString(com.google.protobuf.ByteString) PubsubMessage(com.google.pubsub.v1.PubsubMessage) Test(org.junit.Test)

Example 3 with Schema

use of com.google.pubsub.v1.Schema in project policies-ui-backend by RedHatInsights.

the class OapiTest method validateOpenApi.

@Test
void validateOpenApi() throws Exception {
    OpenApi3 model = new OpenApi3Parser().parse(url, true);
    System.out.printf("OpenAPI Model at %s\n", url);
    if (!model.isValid()) {
        for (ValidationResults.ValidationItem item : model.getValidationItems()) {
            System.err.println(item);
        }
        fail("OpenAPI spec is not valid");
    }
    // 
    // Now that basic validation is done, we can add some of our own
    // 
    Map<String, Path> paths = model.getPaths();
    Map<String, Schema> schemas = model.getSchemas();
    // The base path filler. See also OASModifier.mangleName
    assertTrue(paths.containsKey("/"));
    // User config is private, so don't show it
    assertFalse(paths.containsKey("/user-config"));
    assertFalse(schemas.containsKey("SettingsValues"));
    // Check that openapi does not (again) collapse parameters
    assertEquals(9, paths.get("/policies").getOperation("get").getParameters().size());
    // Check that all properties are present ( https://github.com/smallrye/smallrye-open-api/issues/437 )
    Map<String, Schema> policyProperties = schemas.get("Policy").getProperties();
    assertEquals(9, policyProperties.size());
    assertTrue(policyProperties.containsKey("ctime"));
    assertTrue(policyProperties.containsKey("mtime"));
    // Now that the OpenAPI file has been validated, save a copy to the filesystem
    // This file is going to be uploaded in a regular CI build to know the API state
    // for a given build.
    InputStream in = url.openStream();
    Files.copy(in, Paths.get(TARGET_OPENAPI), StandardCopyOption.REPLACE_EXISTING);
}
Also used : Path(com.reprezen.kaizen.oasparser.model3.Path) ValidationResults(com.reprezen.kaizen.oasparser.val.ValidationResults) InputStream(java.io.InputStream) Schema(com.reprezen.kaizen.oasparser.model3.Schema) OpenApi3Parser(com.reprezen.kaizen.oasparser.OpenApi3Parser) OpenApi3(com.reprezen.kaizen.oasparser.model3.OpenApi3) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 4 with Schema

use of com.google.pubsub.v1.Schema in project java-pubsub by googleapis.

the class SchemaServiceClient method deleteSchema.

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
 * Deletes a schema.
 *
 * <p>Sample code:
 *
 * <pre>{@code
 * try (SchemaServiceClient schemaServiceClient = SchemaServiceClient.create()) {
 *   SchemaName name = SchemaName.of("[PROJECT]", "[SCHEMA]");
 *   schemaServiceClient.deleteSchema(name);
 * }
 * }</pre>
 *
 * @param name Required. Name of the schema to delete. Format is
 *     `projects/{project}/schemas/{schema}`.
 * @throws com.google.api.gax.rpc.ApiException if the remote call fails
 */
public final void deleteSchema(SchemaName name) {
    DeleteSchemaRequest request = DeleteSchemaRequest.newBuilder().setName(name == null ? null : name.toString()).build();
    deleteSchema(request);
}
Also used : DeleteSchemaRequest(com.google.pubsub.v1.DeleteSchemaRequest)

Example 5 with Schema

use of com.google.pubsub.v1.Schema in project java-pubsub by googleapis.

the class SchemaServiceClientTest method listSchemasTest2.

@Test
public void listSchemasTest2() throws Exception {
    Schema responsesElement = Schema.newBuilder().build();
    ListSchemasResponse expectedResponse = ListSchemasResponse.newBuilder().setNextPageToken("").addAllSchemas(Arrays.asList(responsesElement)).build();
    mockSchemaService.addResponse(expectedResponse);
    String parent = "parent-995424086";
    ListSchemasPagedResponse pagedListResponse = client.listSchemas(parent);
    List<Schema> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getSchemasList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockSchemaService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListSchemasRequest actualRequest = ((ListSchemasRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListSchemasRequest(com.google.pubsub.v1.ListSchemasRequest) ListSchemasPagedResponse(com.google.cloud.pubsub.v1.SchemaServiceClient.ListSchemasPagedResponse) AbstractMessage(com.google.protobuf.AbstractMessage) Schema(com.google.pubsub.v1.Schema) ListSchemasResponse(com.google.pubsub.v1.ListSchemasResponse) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)49 Schema (org.molgenis.emx2.Schema)34 QName (javax.xml.namespace.QName)16 Schema (com.google.pubsub.v1.Schema)15 File (java.io.File)15 IOException (java.io.IOException)15 Schema (org.geosdi.geoplatform.xml.xsd.v2001.Schema)15 URL (java.net.URL)14 LayerSchemaDTO (org.geosdi.geoplatform.connector.wfs.response.LayerSchemaDTO)14 StringWriter (java.io.StringWriter)13 Schema (org.oasisopen.odata.csdl.v4.Schema)13 ByteString (com.google.protobuf.ByteString)11 JAXBElement (javax.xml.bind.JAXBElement)10 AbstractMessage (com.google.protobuf.AbstractMessage)9 PrintWriter (java.io.PrintWriter)8 Schema (org.geotoolkit.xsd.xml.v2001.Schema)8 TEntityType (org.oasisopen.odata.csdl.v4.TEntityType)8 ProjectName (com.google.pubsub.v1.ProjectName)7 SchemaName (com.google.pubsub.v1.SchemaName)7 Arrays (java.util.Arrays)7