Skip to content
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

[#3165] fix(client-java): Fix the http client toJson encode without UTF-8 #3179

Merged
merged 6 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,33 @@ public void testCreateFileset() throws IOException {
Fileset.Type.MANAGED, fileset3.type(), "fileset type should be MANAGED by default");
}

@Test
public void testCreateFilesetWithChinese() throws IOException {
// create fileset
String filesetName = "test_create_fileset_with_chinese";
String storageLocation = storageLocation(filesetName) + "/中文目录test";
Assertions.assertFalse(
hdfs.exists(new Path(storageLocation)), "storage location should not exists");
Fileset fileset =
createFileset(
filesetName,
"这是中文comment",
Fileset.Type.MANAGED,
storageLocation,
ImmutableMap.of("k1", "v1", "test", "中文测试test", "中文key", "test1"));

// verify fileset is created
assertFilesetExists(filesetName);
Assertions.assertNotNull(fileset, "fileset should be created");
Assertions.assertEquals("这是中文comment", fileset.comment());
Assertions.assertEquals(Fileset.Type.MANAGED, fileset.type());
Assertions.assertEquals(storageLocation, fileset.storageLocation());
Assertions.assertEquals(3, fileset.properties().size());
Assertions.assertEquals("v1", fileset.properties().get("k1"));
Assertions.assertEquals("中文测试test", fileset.properties().get("test"));
Assertions.assertEquals("test1", fileset.properties().get("中文key"));
}

@Test
public void testExternalFileset() throws IOException {
// create fileset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ public HTTPClient build() {

private StringEntity toJson(Object requestBody) {
try {
return new StringEntity(mapper.writeValueAsString(requestBody));
return new StringEntity(mapper.writeValueAsString(requestBody), StandardCharsets.UTF_8);
} catch (JsonProcessingException e) {
throw new RESTException(e, "Failed to write request body: %s", requestBody);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,27 @@ public void testCreateCatalogWithoutProperties() {
metalake.dropCatalog(catalogIdent);
}

@Test
public void testCreateCatalogWithChinese() {
String catalogName = GravitinoITUtils.genRandomName("catalogz");
NameIdentifier catalogIdent = NameIdentifier.of(metalakeName, catalogName);
Assertions.assertFalse(metalake.catalogExists(catalogIdent));

Map<String, String> properties = Maps.newHashMap();
properties.put("metastore.uris", hmsUri);
metalake.createCatalog(
catalogIdent, Catalog.Type.RELATIONAL, "hive", "这是中文comment", properties);
Assertions.assertTrue(metalake.catalogExists(catalogIdent));
Catalog catalog = metalake.loadCatalog(catalogIdent);
Assertions.assertEquals(catalogName, catalog.name());
Assertions.assertEquals(Catalog.Type.RELATIONAL, catalog.type());
Assertions.assertEquals("hive", catalog.provider());
Assertions.assertEquals("这是中文comment", catalog.comment());
Assertions.assertTrue(catalog.properties().containsKey("metastore.uris"));

metalake.dropCatalog(catalogIdent);
}

@Test
public void testListCatalogsInfo() {
String relCatalogName = GravitinoITUtils.genRandomName("rel_catalog_");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,25 @@ public void testCreateMetalake() {
});
}

@Test
public void testCreateMetalakeWithChinese() {
client.createMetalake(
NameIdentifier.parse(metalakeNameA), "这是中文comment", Collections.emptyMap());
GravitinoMetalake metalake = client.loadMetalake(NameIdentifier.of(metalakeNameA));
assertEquals(metalakeNameA, metalake.name());
assertEquals("这是中文comment", metalake.comment());
assertEquals(AuthConstants.ANONYMOUS_USER, metalake.auditInfo().creator());

// Test metalake name already exists
Map<String, String> emptyMap = Collections.emptyMap();
NameIdentifier exists = NameIdentifier.parse(metalakeNameA);
assertThrows(
MetalakeAlreadyExistsException.class,
() -> {
client.createMetalake(exists, "metalake A comment", emptyMap);
});
}

@Test
public void testDropMetalakes() {
GravitinoMetalake metalakeA =
Expand Down
Loading