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);
}
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"));
}
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);
}
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);
}
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()));
}
Aggregations