-
Notifications
You must be signed in to change notification settings - Fork 31
Scheme client updates #378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
scheme/src/main/java/tech/ydb/scheme/description/Entry.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| package tech.ydb.scheme.description; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| import tech.ydb.proto.scheme.SchemeOperationProtos; | ||
|
|
||
| /** | ||
| * | ||
| * @author Aleksandr Gorshenin | ||
| */ | ||
| public class Entry { | ||
| private final String name; | ||
| private final String owner; | ||
| private final EntryType type; | ||
| private final long sizeBytes; | ||
|
|
||
| public Entry(SchemeOperationProtos.Entry pb) { | ||
| this.name = pb.getName(); | ||
| this.owner = pb.getOwner(); | ||
| this.type = EntryType.fromCode(pb.getTypeValue()); | ||
| this.sizeBytes = pb.getSizeBytes(); | ||
| } | ||
|
|
||
| /** | ||
| * @return Name of scheme entry (dir2 of /dir1/dir2) | ||
| */ | ||
| public String getName() { | ||
| return this.name; | ||
| } | ||
|
|
||
| /** | ||
| * @return SID (Security ID) of user or group | ||
| */ | ||
| public String getOwner() { | ||
| return this.owner; | ||
| } | ||
|
|
||
| /** | ||
| * Size of entry in bytes. Currently filled for: | ||
alex268 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * <ul> | ||
| * <li> TABLE </li> | ||
| * <li> DATABASE </li> | ||
| * </ul> | ||
| * Empty (zero) in other cases. | ||
| * | ||
| * @return Size of entry in bytes | ||
| */ | ||
| public long getSizeBytes() { | ||
| return this.sizeBytes; | ||
| } | ||
|
|
||
| public EntryType getType() { | ||
| return this.type; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(name, owner, type, sizeBytes); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object obj) { | ||
| if (this == obj) { | ||
| return true; | ||
| } | ||
| if (obj == null || obj.getClass() != Entry.class) { | ||
| return false; | ||
| } | ||
| Entry o = (Entry) obj; | ||
| return Objects.equals(name, o.name) | ||
| && Objects.equals(owner, o.owner) | ||
| && type == o.type | ||
| && sizeBytes == o.sizeBytes; | ||
alex268 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "Entry{name='" + name + "'" | ||
| + (owner == null || owner.isEmpty() ? "" : ", owner='" + owner + "'") | ||
| + ", type=" + type | ||
| + (sizeBytes == 0 ? "" : ", size=" + Long.toUnsignedString(sizeBytes)) | ||
| + "}"; | ||
| } | ||
| } | ||
|
|
||
44 changes: 44 additions & 0 deletions
44
scheme/src/main/java/tech/ydb/scheme/description/EntryType.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package tech.ydb.scheme.description; | ||
|
|
||
| /** | ||
| * | ||
| * @author Aleksandr Gorshenin | ||
| */ | ||
| public enum EntryType { | ||
| UNSPECIFIED(0), | ||
|
|
||
| DIRECTORY(1), | ||
| TABLE(2), | ||
| PERS_QUEUE_GROUP(3), | ||
| DATABASE(4), | ||
| RTMR_VOLUME(5), | ||
| BLOCK_STORE_VOLUME(6), | ||
| COORDINATION_NODE(7), | ||
| COLUMN_STORE(12), | ||
| COLUMN_TABLE(13), | ||
| SEQUENCE(15), | ||
| REPLICATION(16), | ||
| TOPIC(17), | ||
| EXTERNAL_TABLE(18), | ||
| EXTERNAL_DATA_SOURCE(19), | ||
| VIEW(20); | ||
|
|
||
| private final int code; | ||
|
|
||
| EntryType(int code) { | ||
| this.code = code; | ||
| } | ||
|
|
||
| public int getCode() { | ||
| return code; | ||
| } | ||
|
|
||
| public static EntryType fromCode(int code) { | ||
| for (EntryType type: EntryType.values()) { | ||
| if (code == type.code) { | ||
| return type; | ||
| } | ||
| } | ||
| return UNSPECIFIED; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
scheme/src/test/java/tech/ydb/scheme/BaseIntegrationTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| package tech.ydb.scheme; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| import org.junit.AfterClass; | ||
| import org.junit.Assert; | ||
| import org.junit.ClassRule; | ||
| import org.junit.Test; | ||
|
|
||
| import tech.ydb.core.Result; | ||
| import tech.ydb.core.Status; | ||
| import tech.ydb.core.StatusCode; | ||
| import tech.ydb.scheme.description.DescribePathResult; | ||
| import tech.ydb.scheme.description.Entry; | ||
| import tech.ydb.scheme.description.EntryType; | ||
| import tech.ydb.scheme.description.ListDirectoryResult; | ||
| import tech.ydb.test.junit4.GrpcTransportRule; | ||
|
|
||
| /** | ||
| * | ||
| * @author Aleksandr Gorshenin | ||
| */ | ||
| public class BaseIntegrationTest { | ||
| @ClassRule | ||
| public final static GrpcTransportRule transport = new GrpcTransportRule(); | ||
|
|
||
| private final static SchemeClient client = SchemeClient.newClient(transport).build(); | ||
|
|
||
| @AfterClass | ||
| public static void close() { | ||
| client.close(); | ||
| } | ||
|
|
||
| @Test | ||
| public void rootPathTest() { | ||
| Result<DescribePathResult> describeRoot = client.describePath("/").join(); | ||
| Assert.assertTrue(describeRoot.isSuccess()); | ||
| DescribePathResult root = describeRoot.getValue(); | ||
| Assert.assertEquals("/", root.getEntry().getName()); | ||
| Assert.assertEquals("", root.getEntry().getOwner()); | ||
|
|
||
| Result<ListDirectoryResult> listRoot = client.listDirectory("/").join(); | ||
| Assert.assertTrue(listRoot.isSuccess()); | ||
| ListDirectoryResult listResult = listRoot.getValue(); | ||
| Assert.assertEquals("/", listResult.getEntry().getName()); | ||
| Assert.assertEquals("", listResult.getEntry().getOwner()); | ||
| Assert.assertEquals("/", listResult.getEntry().getName()); | ||
| Assert.assertEquals(0l, listResult.getEntry().getSizeBytes()); | ||
| Assert.assertEquals(EntryType.DIRECTORY, listResult.getEntry().getType()); | ||
| Assert.assertEquals("Entry{name='/', type=DIRECTORY}", listResult.getEntry().toString()); | ||
|
|
||
|
|
||
| Assert.assertEquals(1, listResult.getEntryChildren().size()); | ||
| listResult.getEntryChildren().get(0); | ||
| Entry firstChild = listResult.getEntryChildren().get(0); | ||
| Assert.assertTrue(transport.getDatabase().startsWith("/" + firstChild.getName())); | ||
| Assert.assertEquals(EntryType.DIRECTORY, firstChild.getType()); | ||
| } | ||
|
|
||
| @Test | ||
| public void invalidPathTest() { | ||
| Result<DescribePathResult> describeInvalid = client.describePath("/invalid-path").join(); | ||
| Assert.assertFalse(describeInvalid.isSuccess()); | ||
| Assert.assertEquals(StatusCode.SCHEME_ERROR, describeInvalid.getStatus().getCode()); | ||
| Assert.assertEquals( | ||
| "Status{code = SCHEME_ERROR(code=400070), issues = [Root not found (S_ERROR)]}", | ||
alex268 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| describeInvalid.getStatus().toString() | ||
| ); | ||
|
|
||
| Result<ListDirectoryResult> listInvalid = client.listDirectory("/invalid-path").join(); | ||
| Assert.assertFalse(listInvalid.isSuccess()); | ||
| Assert.assertEquals(StatusCode.SCHEME_ERROR, listInvalid.getStatus().getCode()); | ||
| Assert.assertEquals( | ||
| "Status{code = SCHEME_ERROR(code=400070), issues = [Root not found (S_ERROR)]}", | ||
| listInvalid.getStatus().toString() | ||
| ); | ||
|
|
||
| Status makeDirectory= client.makeDirectory("/invalid-path").join(); | ||
| Assert.assertFalse(makeDirectory.isSuccess()); | ||
| Assert.assertEquals(StatusCode.BAD_REQUEST, makeDirectory.getCode()); | ||
|
|
||
| Status removeDirectory= client.removeDirectory("/invalid-path").join(); | ||
| Assert.assertFalse(removeDirectory.isSuccess()); | ||
| Assert.assertEquals(StatusCode.SCHEME_ERROR, removeDirectory.getCode()); | ||
| Assert.assertEquals( | ||
| "Status{code = SCHEME_ERROR(code=400070), issues = [#200200 Path does not exist (S_ERROR)]}", | ||
| removeDirectory.toString() | ||
| ); | ||
| } | ||
|
|
||
| @Test | ||
| public void createAndDeleteTest() { | ||
| String basePath = transport.getDatabase(); | ||
| String dirName = "test_dir"; | ||
|
|
||
| Status dirCreate1 = client.makeDirectory(basePath + "/" + dirName).join(); | ||
| Assert.assertTrue(dirCreate1.isSuccess()); | ||
|
|
||
| // Directory creating is idempotent | ||
| Status dirCreate2 = client.makeDirectory(basePath + "/" + dirName).join(); | ||
| Assert.assertTrue(dirCreate2.isSuccess()); | ||
|
|
||
| Result<DescribePathResult> dirEntry = client.describePath(basePath + "/" + dirName).join(); | ||
| Assert.assertTrue(dirEntry.isSuccess()); | ||
| Assert.assertEquals(dirName, dirEntry.getValue().getEntry().getName()); | ||
|
|
||
| Result<ListDirectoryResult> rootList = client.listDirectory(basePath).join(); | ||
| Assert.assertTrue(rootList.isSuccess()); | ||
| Optional<Entry> child = rootList.getValue().getEntryChildren().stream() | ||
| .filter(e -> dirName.equals(e.getName())).findFirst(); | ||
| Assert.assertTrue(child.isPresent()); | ||
| Assert.assertEquals(child.get(), dirEntry.getValue().getEntry()); | ||
|
|
||
| Status dirDelete = client.removeDirectory(basePath + "/" + dirName).join(); | ||
| Assert.assertTrue(dirDelete.isSuccess()); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <Configuration status="WARN"> | ||
| <Appenders> | ||
| <Console name="Console" target="SYSTEM_OUT"> | ||
| <PatternLayout pattern="[%level] %d{HH:mm:ss.SSS} [%t] %logger{36} - %msg%n"/> | ||
| </Console> | ||
| </Appenders> | ||
|
|
||
| <Loggers> | ||
| <Logger name="io.grpc" level="warn" additivity="false"> | ||
| <AppenderRef ref="Console"/> | ||
| </Logger> | ||
| <Logger name="tech.ydb.core.grpc" level="trace" additivity="false"> | ||
| <AppenderRef ref="Console"/> | ||
| </Logger> | ||
|
|
||
| <!-- https://www.testcontainers.org/supported_docker_environment/logging_config/ --> | ||
| <Logger name="org.testcontainers" level="warn" /> | ||
| <Logger name="com.github.dockerjava" level="warn"/> | ||
| <Logger name="com.github.dockerjava.zerodep.shaded.org.apache.hc.client5.http.wire" level="off"/> | ||
|
|
||
| <Root level="debug" > | ||
| <AppenderRef ref="Console"/> | ||
| </Root> | ||
| </Loggers> | ||
| </Configuration> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.