You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2023/02/23 15:48:03 UTC
[skywalking-banyandb-java-client] branch main updated: Tweak Group builders for property operations (#36)
This is an automated email from the ASF dual-hosted git repository.
wusheng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-banyandb-java-client.git
The following commit(s) were added to refs/heads/main by this push:
new f359492 Tweak Group builders for property operations (#36)
f359492 is described below
commit f35949233108439ed84aaa089f7ab826fd0cc086
Author: Gao Hongtao <ha...@gmail.com>
AuthorDate: Thu Feb 23 23:47:57 2023 +0800
Tweak Group builders for property operations (#36)
---
.../banyandb/v1/client/metadata/Group.java | 45 ++++++++++++++++------
.../banyandb/v1/client/BanyanDBClientTestCI.java | 2 +-
.../v1/client/ITBanyanDBPropertyTests.java | 8 +---
3 files changed, 36 insertions(+), 19 deletions(-)
diff --git a/src/main/java/org/apache/skywalking/banyandb/v1/client/metadata/Group.java b/src/main/java/org/apache/skywalking/banyandb/v1/client/metadata/Group.java
index a306ba8..4fcca7d 100644
--- a/src/main/java/org/apache/skywalking/banyandb/v1/client/metadata/Group.java
+++ b/src/main/java/org/apache/skywalking/banyandb/v1/client/metadata/Group.java
@@ -19,9 +19,11 @@
package org.apache.skywalking.banyandb.v1.client.metadata;
import com.google.auto.value.AutoValue;
+import com.google.common.base.Preconditions;
import org.apache.skywalking.banyandb.common.v1.BanyandbCommon;
import org.apache.skywalking.banyandb.v1.client.util.TimeUtils;
+import javax.annotation.Nullable;
import java.time.ZonedDateTime;
@AutoValue
@@ -36,33 +38,54 @@ public abstract class Group extends NamedSchema<BanyandbCommon.Group> {
*/
abstract int shardNum();
+ @Nullable
abstract IntervalRule blockInterval();
+ @Nullable
abstract IntervalRule segmentInterval();
+ @Nullable
abstract IntervalRule ttl();
public static Group create(String name, Catalog catalog, int shardNum, IntervalRule blockInterval, IntervalRule segmentInterval, IntervalRule ttl) {
+ Preconditions.checkArgument(shardNum > 0, "shardNum should more than 0");
+ Preconditions.checkNotNull(blockInterval, "blockInterval is null");
+ Preconditions.checkNotNull(segmentInterval, "segmentInterval is null");
+ Preconditions.checkNotNull(ttl, "ttl is null");
return new AutoValue_Group(null, name, null, catalog, shardNum, blockInterval, segmentInterval, ttl);
}
public static Group create(String name, Catalog catalog, int shardNum, IntervalRule blockInterval, IntervalRule segmentInterval, IntervalRule ttl, ZonedDateTime updatedAt) {
+ Preconditions.checkArgument(shardNum > 0, "shardNum should more than 0");
+ Preconditions.checkNotNull(blockInterval, "blockInterval is null");
+ Preconditions.checkNotNull(segmentInterval, "segmentInterval is null");
+ Preconditions.checkNotNull(ttl, "ttl is null");
return new AutoValue_Group(null, name, updatedAt, catalog, shardNum, blockInterval, segmentInterval, ttl);
}
- @Override
+ public static Group create(String name) {
+ return new AutoValue_Group(null, name, null, Catalog.UNSPECIFIED, 0, null, null, null);
+ }
+
+ public static Group create(String name, ZonedDateTime updatedAt) {
+ return new AutoValue_Group(null, name, updatedAt, Catalog.UNSPECIFIED, 0, null, null, null);
+ }
+
+ @Override
public BanyandbCommon.Group serialize() {
- return BanyandbCommon.Group.newBuilder()
+ BanyandbCommon.Group.Builder builder = BanyandbCommon.Group.newBuilder()
// use name as the group
.setMetadata(this.buildMetadata().toBuilder())
- .setCatalog(catalog().getCatalog())
- .setResourceOpts(BanyandbCommon.ResourceOpts.newBuilder()
+ .setCatalog(catalog().getCatalog());
+ if (shardNum() > 0) {
+ builder.setResourceOpts(BanyandbCommon.ResourceOpts.newBuilder()
.setShardNum(shardNum())
.setBlockInterval(blockInterval().serialize())
.setSegmentInterval(segmentInterval().serialize())
.setTtl(ttl().serialize())
- .build())
- .build();
+ .build());
+ }
+ return builder.build();
}
public static Group fromProtobuf(BanyandbCommon.Group group) {
@@ -75,14 +98,14 @@ public abstract class Group extends NamedSchema<BanyandbCommon.Group> {
catalog = Catalog.MEASURE;
break;
}
-
+ BanyandbCommon.ResourceOpts opts = group.getResourceOpts();
return new AutoValue_Group(null,
group.getMetadata().getName(),
TimeUtils.parseTimestamp(group.getUpdatedAt()),
catalog,
- group.getResourceOpts().getShardNum(),
- IntervalRule.fromProtobuf(group.getResourceOpts().getBlockInterval()),
- IntervalRule.fromProtobuf(group.getResourceOpts().getSegmentInterval()),
- IntervalRule.fromProtobuf(group.getResourceOpts().getTtl()));
+ opts == null ? 0 : opts.getShardNum(),
+ opts == null ? null : IntervalRule.fromProtobuf(opts.getBlockInterval()),
+ opts == null ? null : IntervalRule.fromProtobuf(opts.getSegmentInterval()),
+ opts == null ? null : IntervalRule.fromProtobuf(opts.getTtl()));
}
}
diff --git a/src/test/java/org/apache/skywalking/banyandb/v1/client/BanyanDBClientTestCI.java b/src/test/java/org/apache/skywalking/banyandb/v1/client/BanyanDBClientTestCI.java
index 0bcaa5b..d91f987 100644
--- a/src/test/java/org/apache/skywalking/banyandb/v1/client/BanyanDBClientTestCI.java
+++ b/src/test/java/org/apache/skywalking/banyandb/v1/client/BanyanDBClientTestCI.java
@@ -30,7 +30,7 @@ import java.io.IOException;
public class BanyanDBClientTestCI {
private static final String REGISTRY = "ghcr.io";
private static final String IMAGE_NAME = "apache/skywalking-banyandb";
- private static final String TAG = "1c19243df23f8350ea5c1542fd914c49e8698960";
+ private static final String TAG = "adbd3e87df7f84e5d1904fcf40476d2e81842058";
private static final String IMAGE = REGISTRY + "/" + IMAGE_NAME + ":" + TAG;
diff --git a/src/test/java/org/apache/skywalking/banyandb/v1/client/ITBanyanDBPropertyTests.java b/src/test/java/org/apache/skywalking/banyandb/v1/client/ITBanyanDBPropertyTests.java
index 1d7303d..b2eaf03 100644
--- a/src/test/java/org/apache/skywalking/banyandb/v1/client/ITBanyanDBPropertyTests.java
+++ b/src/test/java/org/apache/skywalking/banyandb/v1/client/ITBanyanDBPropertyTests.java
@@ -20,9 +20,7 @@ package org.apache.skywalking.banyandb.v1.client;
import io.grpc.Status;
import org.apache.skywalking.banyandb.v1.client.grpc.exception.BanyanDBException;
-import org.apache.skywalking.banyandb.v1.client.metadata.Catalog;
import org.apache.skywalking.banyandb.v1.client.metadata.Group;
-import org.apache.skywalking.banyandb.v1.client.metadata.IntervalRule;
import org.apache.skywalking.banyandb.v1.client.metadata.Property;
import org.junit.After;
import org.junit.Assert;
@@ -38,11 +36,7 @@ public class ITBanyanDBPropertyTests extends BanyanDBClientTestCI {
@Before
public void setUp() throws IOException, BanyanDBException, InterruptedException {
super.setUpConnection();
- Group expectedGroup = this.client.define(
- Group.create("default", Catalog.STREAM, 2, IntervalRule.create(IntervalRule.Unit.HOUR, 4),
- IntervalRule.create(IntervalRule.Unit.DAY, 1),
- IntervalRule.create(IntervalRule.Unit.DAY, 7))
- );
+ Group expectedGroup = this.client.define(Group.create("default"));
Assert.assertNotNull(expectedGroup);
}