Refine search
@Test public void testSerialize() { assertEquals(PARAMETER_KIND_CODEC.toJson(ParameterKind.TYPE), "\"TYPE_SIGNATURE\""); assertEquals(PARAMETER_KIND_CODEC.toJson(ParameterKind.NAMED_TYPE), "\"NAMED_TYPE_SIGNATURE\""); assertEquals(PARAMETER_KIND_CODEC.toJson(ParameterKind.LONG), "\"LONG_LITERAL\""); assertEquals(PARAMETER_KIND_CODEC.toJson(ParameterKind.VARIABLE), "\"VARIABLE\""); }
private static void assertJsonRoundTrip(ClientTypeSignature signature) { String json = CLIENT_TYPE_SIGNATURE_CODEC.toJson(signature); ClientTypeSignature copy = CLIENT_TYPE_SIGNATURE_CODEC.fromJson(json); assertEquals(copy, signature); } }
public static void validatePersonJsonCodec(JsonCodec<ImmutablePerson> jsonCodec) { ImmutablePerson expected = new ImmutablePerson("dain", true); String json = jsonCodec.toJson(expected); assertEquals(jsonCodec.fromJson(json), expected); byte[] bytes = jsonCodec.toJsonBytes(expected); assertEquals(jsonCodec.fromJson(bytes), expected); }
public static <T> void assertJsonRoundTrip(JsonCodec<T> codec, T object) { String json = codec.toJson(object); T copy = codec.fromJson(json); assertEquals(copy, object); } }
public static void validatePersonJsonCodec(JsonCodec<ImmutablePerson> jsonCodec) { ImmutablePerson expected = new ImmutablePerson("dain", true); String json = jsonCodec.toJson(expected); assertEquals(jsonCodec.fromJson(json), expected); byte[] bytes = jsonCodec.toJsonBytes(expected); assertEquals(jsonCodec.fromJson(bytes), expected); }
@Test public void testMatch() { ResourceGroupId resourceGroupId1 = new ResourceGroupId(ImmutableList.of("global", "test", "user", "insert")); ResourceGroupId resourceGroupId2 = new ResourceGroupId(ImmutableList.of("global", "test", "user", "select")); dao.insertExactMatchSelector("test", "@test@test_pipeline", INSERT.name(), CODEC.toJson(resourceGroupId1)); dao.insertExactMatchSelector("test", "@test@test_pipeline", SELECT.name(), CODEC.toJson(resourceGroupId2)); DbSourceExactMatchSelector selector = new DbSourceExactMatchSelector("test", dao); assertEquals( selector.match(new SelectionCriteria(true, "testuser", Optional.of("@test@test_pipeline"), ImmutableSet.of("tag"), EMPTY_RESOURCE_ESTIMATES, Optional.empty())), Optional.empty()); assertEquals( selector.match(new SelectionCriteria(true, "testuser", Optional.of("@test@test_pipeline"), ImmutableSet.of("tag"), EMPTY_RESOURCE_ESTIMATES, Optional.of(INSERT.name()))).map(SelectionContext::getResourceGroupId), Optional.of(resourceGroupId1)); assertEquals( selector.match(new SelectionCriteria(true, "testuser", Optional.of("@test@test_pipeline"), ImmutableSet.of("tag"), EMPTY_RESOURCE_ESTIMATES, Optional.of(SELECT.name()))).map(SelectionContext::getResourceGroupId), Optional.of(resourceGroupId2)); assertEquals( selector.match(new SelectionCriteria(true, "testuser", Optional.of("@test@test_pipeline"), ImmutableSet.of("tag"), EMPTY_RESOURCE_ESTIMATES, Optional.of(DELETE.name()))), Optional.empty()); assertEquals( selector.match(new SelectionCriteria(true, "testuser", Optional.of("@test@test_new"), ImmutableSet.of(), EMPTY_RESOURCE_ESTIMATES, Optional.of(INSERT.name()))), Optional.empty()); } }
@Test public void testJsonRoundTripEmptyThings() { AccumuloSplit expected = new AccumuloSplit( "accumulo", "schema", "table", "id", LexicoderRowSerializer.class.getCanonicalName(), ImmutableList.of(), ImmutableList.of(), Optional.empty(), Optional.empty()); String json = codec.toJson(expected); AccumuloSplit actual = codec.fromJson(json); assertSplit(actual, expected); }
private static void assertJsonRoundTrip(ServerInfo serverInfo) { String json = SERVER_INFO_CODEC.toJson(serverInfo); ServerInfo copy = SERVER_INFO_CODEC.fromJson(json); assertEquals(copy, serverInfo); } }
public static void validatePersonMapJsonCodec(JsonCodec<Map<String, ImmutablePerson>> jsonCodec) { ImmutableMap<String, ImmutablePerson> expected = ImmutableMap.<String, ImmutablePerson>builder() .put("dain", new ImmutablePerson("dain", true)) .put("martin", new ImmutablePerson("martin", true)) .put("mark", new ImmutablePerson("mark", true)) .build(); String json = jsonCodec.toJson(expected); assertEquals(jsonCodec.fromJson(json), expected); byte[] bytes = jsonCodec.toJsonBytes(expected); assertEquals(jsonCodec.fromJson(bytes), expected); }
@Test public void testExactMatchSelector() { H2ResourceGroupsDao dao = setup("exact_match_selector"); dao.createExactMatchSelectorsTable(); ResourceGroupId resourceGroupId1 = new ResourceGroupId(ImmutableList.of("global", "test", "user", "insert")); ResourceGroupId resourceGroupId2 = new ResourceGroupId(ImmutableList.of("global", "test", "user", "select")); JsonCodec<ResourceGroupId> codec = JsonCodec.jsonCodec(ResourceGroupId.class); dao.insertExactMatchSelector("test", "@test@test_pipeline", INSERT.name(), codec.toJson(resourceGroupId1)); dao.insertExactMatchSelector("test", "@test@test_pipeline", SELECT.name(), codec.toJson(resourceGroupId2)); assertNull(dao.getExactMatchResourceGroup("test", "@test@test_pipeline", null)); assertEquals(dao.getExactMatchResourceGroup("test", "@test@test_pipeline", INSERT.name()), codec.toJson(resourceGroupId1)); assertEquals(dao.getExactMatchResourceGroup("test", "@test@test_pipeline", SELECT.name()), codec.toJson(resourceGroupId2)); assertNull(dao.getExactMatchResourceGroup("test", "@test@test_pipeline", DELETE.name())); assertNull(dao.getExactMatchResourceGroup("test", "abc", INSERT.name())); assertNull(dao.getExactMatchResourceGroup("prod", "@test@test_pipeline", INSERT.name())); }
@Test public void testJsonRoundTrip() { String json = TABLE_CODEC.toJson(TABLE); JmxTableHandle copy = TABLE_CODEC.fromJson(json); assertEquals(copy, TABLE); }
public static void validatePersonMapJsonCodec(JsonCodec<Map<String, ImmutablePerson>> jsonCodec) { ImmutableMap<String, ImmutablePerson> expected = ImmutableMap.<String, ImmutablePerson>builder() .put("dain", new ImmutablePerson("dain", true)) .put("martin", new ImmutablePerson("martin", true)) .put("mark", new ImmutablePerson("mark", true)) .build(); String json = jsonCodec.toJson(expected); assertEquals(jsonCodec.fromJson(json), expected); byte[] bytes = jsonCodec.toJsonBytes(expected); assertEquals(jsonCodec.fromJson(bytes), expected); }
@Test public void testGetServerInfo() throws Exception { ServerInfo expected = new ServerInfo(UNKNOWN, "test", true, false, Optional.of(Duration.valueOf("2m"))); server.enqueue(new MockResponse() .addHeader(CONTENT_TYPE, "application/json") .setBody(SERVER_INFO_CODEC.toJson(expected))); QueryExecutor executor = new QueryExecutor(new OkHttpClient()); ServerInfo actual = executor.getServerInfo(server.url("/v1/info").uri()); assertEquals(actual.getEnvironment(), "test"); assertEquals(actual.getUptime(), Optional.of(Duration.valueOf("2m"))); assertEquals(server.getRequestCount(), 1); assertEquals(server.takeRequest().getPath(), "/v1/info"); } }
@Test public void testJsonRoundTrip() { for (LocalFileColumnHandle handle : columnHandle) { String json = COLUMN_CODEC.toJson(handle); LocalFileColumnHandle copy = COLUMN_CODEC.fromJson(json); assertEquals(copy, handle); } } }
public static void validatePersonListJsonCodec(JsonCodec<List<ImmutablePerson>> jsonCodec) { ImmutableList<ImmutablePerson> expected = ImmutableList.of( new ImmutablePerson("dain", true), new ImmutablePerson("martin", true), new ImmutablePerson("mark", true)); String json = jsonCodec.toJson(expected); assertEquals(jsonCodec.fromJson(json), expected); byte[] bytes = jsonCodec.toJsonBytes(expected); assertEquals(jsonCodec.fromJson(bytes), expected); }
@Test public void testJsonRoundTrip() { String json = COLUMN_CODEC.toJson(columnHandle); ExampleColumnHandle copy = COLUMN_CODEC.fromJson(json); assertEquals(copy, columnHandle); }