Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
coolderli committed Jan 30, 2024
1 parent c3d7ce6 commit 9e0a8c8
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ public static NameIdentifier ofTable(
}

/**
* Create the table {@link NameIdentifier} with the given metalake, catalog, schema and fileset
* Create the fileset {@link NameIdentifier} with the given metalake, catalog, schema and fileset
* name.
*
* @param metalake The metalake name
* @param catalog The catalog name
* @param schema The schema name
* @param fileset The fileset name
* @return The created table {@link NameIdentifier}
* @return The created fileset {@link NameIdentifier}
*/
public static NameIdentifier ofFileset(
String metalake, String catalog, String schema, String fileset) {
Expand Down
2 changes: 1 addition & 1 deletion api/src/main/java/com/datastrato/gravitino/Namespace.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public static Namespace ofTable(String metalake, String catalog, String schema)
* @param metalake The metalake name
* @param catalog The catalog name
* @param schema The schema name
* @return A namespace for table
* @return A namespace for fileset
*/
public static Namespace ofFileset(String metalake, String catalog, String schema) {
return of(metalake, catalog, schema);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;

Expand All @@ -35,6 +36,7 @@ public interface FilesetUpdateRequest extends RESTRequest {
FilesetChange filesetChange();

@EqualsAndHashCode
@NoArgsConstructor(force = true)
@AllArgsConstructor
@ToString
class RenameFilesetRequest implements FilesetUpdateRequest {
Expand All @@ -56,6 +58,7 @@ public void validate() throws IllegalArgumentException {
}

@EqualsAndHashCode
@NoArgsConstructor(force = true)
@AllArgsConstructor
@ToString
class UpdateFilesetCommentRequest implements FilesetUpdateRequest {
Expand All @@ -78,6 +81,7 @@ public void validate() throws IllegalArgumentException {
}

@EqualsAndHashCode
@NoArgsConstructor(force = true)
@AllArgsConstructor
@ToString
class SetFilesetPropertiesRequest implements FilesetUpdateRequest {
Expand All @@ -104,6 +108,7 @@ public void validate() throws IllegalArgumentException {
}

@EqualsAndHashCode
@NoArgsConstructor(force = true)
@AllArgsConstructor
@ToString
class RemoveFilesetPropertiesRequest implements FilesetUpdateRequest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.datastrato.gravitino.rest.RESTRequest;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
Expand All @@ -17,7 +16,7 @@

@Getter
@EqualsAndHashCode
@NoArgsConstructor(access = AccessLevel.PRIVATE, force = true)
@NoArgsConstructor(force = true)
@AllArgsConstructor
@ToString
public class FilesetUpdatesRequest implements RESTRequest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public void loadFileset() {
when(dispatcher.loadFileset(any())).thenReturn(fileset);

Response resp =
target(filesetPath(metalake, catalog, schema) + "table1")
target(filesetPath(metalake, catalog, schema) + "fileset1")
.request(MediaType.APPLICATION_JSON_TYPE)
.accept("application/vnd.gravitino.v1+json")
.get();
Expand All @@ -166,32 +166,31 @@ public void loadFileset() {
Assertions.assertEquals(fileset.properties(), filesetDTO.properties());

// Test throw NoSuchFilesetException
when(dispatcher.loadFileset(any()))
.thenThrow(new NoSuchFilesetException("no such fileset error"));
doThrow(new NoSuchFilesetException("no found")).when(dispatcher).loadFileset(any());
Response resp1 =
target(filesetPath(metalake, catalog, schema) + "table1")
target(filesetPath(metalake, catalog, schema) + "fileset1")
.request(MediaType.APPLICATION_JSON_TYPE)
.accept("application/vnd.gravitino.v1+json")
.get();
Assertions.assertEquals(Response.Status.NOT_FOUND.getStatusCode(), resp.getStatus());
Assertions.assertEquals(Response.Status.NOT_FOUND.getStatusCode(), resp1.getStatus());

ErrorResponse errorResp = resp1.readEntity(ErrorResponse.class);
Assertions.assertEquals(ErrorConstants.NOT_FOUND_CODE, errorResp.getCode());
Assertions.assertEquals(NoSuchFilesetException.class.getSimpleName(), errorResp.getType());

// Test throw RuntimeException
when(dispatcher.loadFileset(any())).thenThrow(new NoSuchFilesetException("internal error"));
doThrow(new RuntimeException("internal error")).when(dispatcher).loadFileset(any());
Response resp2 =
target(filesetPath(metalake, catalog, schema) + "table1")
target(filesetPath(metalake, catalog, schema) + "fileset1")
.request(MediaType.APPLICATION_JSON_TYPE)
.accept("application/vnd.gravitino.v1+json")
.get();
Assertions.assertEquals(
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), resp.getStatus());
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), resp2.getStatus());

ErrorResponse errorResp2 = resp2.readEntity(ErrorResponse.class);
Assertions.assertEquals(ErrorConstants.INTERNAL_ERROR_CODE, errorResp2.getCode());
Assertions.assertEquals(NoSuchFilesetException.class.getSimpleName(), errorResp2.getType());
Assertions.assertEquals(RuntimeException.class.getSimpleName(), errorResp2.getType());
}

@Test
Expand Down Expand Up @@ -441,7 +440,7 @@ private void assertUpdateFileset(FilesetUpdatesRequest req, Fileset updatedFiles

FilesetDTO filesetDTO = filesetResp.getFileset();
Assertions.assertEquals(updatedFileset.name(), filesetDTO.name());
Assertions.assertEquals(updatedFileset.comment(), filesetDTO.name());
Assertions.assertEquals(updatedFileset.comment(), filesetDTO.comment());
Assertions.assertEquals(updatedFileset.type(), filesetDTO.type());
Assertions.assertEquals(updatedFileset.properties(), filesetDTO.properties());
}
Expand Down

0 comments on commit 9e0a8c8

Please sign in to comment.