| /* |
| * Licensed to the Apache Software Foundation (ASF) under one or more |
| * contributor license agreements. See the NOTICE file distributed with |
| * this work for additional information regarding copyright ownership. |
| * The ASF licenses this file to You under the Apache License, Version 2.0 |
| * (the "License"); you may not use this file except in compliance with |
| * the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| * |
| */ |
| |
| package org.apache.skywalking.banyandb.v1.client.metadata; |
| |
| import org.apache.skywalking.banyandb.v1.client.AbstractBanyanDBClientTest; |
| import org.apache.skywalking.banyandb.v1.client.grpc.exception.BanyanDBException; |
| import org.junit.Assert; |
| import org.junit.Before; |
| import org.junit.Test; |
| |
| import java.io.IOException; |
| import java.util.List; |
| |
| public class StreamMetadataRegistryTest extends AbstractBanyanDBClientTest { |
| @Before |
| public void setUp() throws IOException { |
| setUp(bindStreamRegistry()); |
| } |
| |
| @Test |
| public void testStreamRegistry_createAndGet() throws BanyanDBException { |
| Stream expectedStream = Stream.create("default", "sw") |
| .setEntityRelativeTags("service_id", "service_instance_id", "state") |
| .addTagFamily(TagFamilySpec.create("data") |
| .addTagSpec(TagFamilySpec.TagSpec.newBinaryTag("data_binary")) |
| .build()) |
| .addTagFamily(TagFamilySpec.create("searchable") |
| .addTagSpec(TagFamilySpec.TagSpec.newStringTag("trace_id")) |
| .addTagSpec(TagFamilySpec.TagSpec.newIntTag("state")) |
| .addTagSpec(TagFamilySpec.TagSpec.newStringTag("service_id")) |
| .addTagSpec(TagFamilySpec.TagSpec.newStringTag("service_instance_id")) |
| .build()) |
| .addIndex(IndexRule.create("trace_id", IndexRule.IndexType.INVERTED)) |
| .build(); |
| this.client.define(expectedStream); |
| Assert.assertTrue(streamRegistry.containsKey("sw")); |
| Stream actualStream = client.findStream("default", "sw"); |
| Assert.assertNotNull(actualStream); |
| Assert.assertEquals(expectedStream, actualStream); |
| Assert.assertNotNull(actualStream.updatedAt()); |
| Assert.assertNotNull(actualStream.modRevision()); |
| } |
| |
| @Test |
| public void testStreamRegistry_createAndList() throws BanyanDBException { |
| Stream expectedStream = Stream.create("default", "sw") |
| .setEntityRelativeTags("service_id", "service_instance_id", "state") |
| .addTagFamily(TagFamilySpec.create("data") |
| .addTagSpec(TagFamilySpec.TagSpec.newBinaryTag("data_binary")) |
| .build()) |
| .addTagFamily(TagFamilySpec.create("searchable") |
| .addTagSpec(TagFamilySpec.TagSpec.newStringTag("trace_id")) |
| .addTagSpec(TagFamilySpec.TagSpec.newIntTag("state")) |
| .addTagSpec(TagFamilySpec.TagSpec.newStringTag("service_id")) |
| .build()) |
| .addIndex(IndexRule.create("trace_id", IndexRule.IndexType.INVERTED)) |
| .build(); |
| client.define(expectedStream); |
| List<Stream> actualStreams = new StreamMetadataRegistry(this.channel).list("default"); |
| Assert.assertNotNull(actualStreams); |
| Assert.assertEquals(1, actualStreams.size()); |
| actualStreams.forEach(stream -> Assert.assertNotNull(stream.modRevision())); |
| } |
| |
| @Test |
| public void testStreamRegistry_createAndDelete() throws BanyanDBException { |
| Stream expectedStream = Stream.create("default", "sw") |
| .setEntityRelativeTags("service_id", "service_instance_id", "state") |
| .addTagFamily(TagFamilySpec.create("data") |
| .addTagSpec(TagFamilySpec.TagSpec.newBinaryTag("data_binary")) |
| .build()) |
| .addTagFamily(TagFamilySpec.create("searchable") |
| .addTagSpec(TagFamilySpec.TagSpec.newStringTag("trace_id")) |
| .addTagSpec(TagFamilySpec.TagSpec.newIntTag("state")) |
| .addTagSpec(TagFamilySpec.TagSpec.newStringTag("service_id")) |
| .build()) |
| .addIndex(IndexRule.create("trace_id", IndexRule.IndexType.INVERTED)) |
| .build(); |
| this.client.define(expectedStream); |
| boolean deleted = this.client.delete(expectedStream); |
| Assert.assertTrue(deleted); |
| Assert.assertEquals(0, streamRegistry.size()); |
| } |
| } |