valepakh commented on code in PR #6931: URL: https://github.com/apache/ignite-3/pull/6931#discussion_r2513515515
########## modules/java-records-tests/src/integrationTest/java/org/apache/ignite/internal/schema/marshaller/ItTableViewTest.java: ########## @@ -0,0 +1,165 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.schema.marshaller; + +import static org.apache.ignite.internal.lang.IgniteStringFormatter.format; +import static org.apache.ignite.internal.schema.marshaller.AssertMarshaller.assertView; +import static org.apache.ignite.internal.schema.marshaller.AssertMarshaller.assertViewThrows; +import static org.junit.jupiter.api.Named.named; +import static org.junit.jupiter.params.provider.Arguments.arguments; + +import java.util.stream.Stream; +import org.apache.ignite.client.IgniteClient; +import org.apache.ignite.internal.ClusterPerClassIntegrationTest; +import org.apache.ignite.internal.schema.marshaller.Records.ComponentsExact; +import org.apache.ignite.internal.schema.marshaller.Records.ComponentsNarrow; +import org.apache.ignite.internal.schema.marshaller.Records.ComponentsReordered; +import org.apache.ignite.internal.schema.marshaller.Records.ComponentsWide; +import org.apache.ignite.internal.schema.marshaller.Records.ComponentsWrongTypes; +import org.apache.ignite.internal.schema.marshaller.Records.NotAnnotatedNotMapped; +import org.apache.ignite.internal.util.IgniteUtils; +import org.apache.ignite.lang.MarshallerException; +import org.apache.ignite.table.Table; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +/** + * Ensures that records and classes behave the same way. + */ +class ItTableViewTest extends ClusterPerClassIntegrationTest { + private static final String TBL = "TBL"; + private static IgniteClient CLIENT; + private static Table TABLE_EMBEDDED; + private static Table TABLE_CLIENT; + + private static Stream<Arguments> tableImpls() { + return Stream.of( + arguments(named("embedded", TABLE_EMBEDDED)), + arguments(named("client", TABLE_CLIENT)) + ); + } + + @BeforeAll + static void beforeAll() { + CLIENT = IgniteClient.builder() + .addresses("localhost:10800") + .build(); + + sql(format(Records.SQL_PATTERN, TBL)); + + TABLE_EMBEDDED = CLUSTER.aliveNode().tables().table(TBL); + TABLE_CLIENT = CLIENT.tables().table(TBL); + } + + @AfterEach + void tearDown() { + sql("DELETE FROM " + TBL + ";"); + } + + @AfterAll + static void afterAll() throws Exception { + IgniteUtils.closeAll(CLIENT); Review Comment: ```suggestion CLIENT.close(); ``` ########## modules/java-records-tests/src/testFixtures/java/org/apache/ignite/internal/schema/marshaller/AssertMarshaller.java: ########## @@ -0,0 +1,111 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.schema.marshaller; + +import static org.apache.ignite.internal.schema.marshaller.Records.schema; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.not; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.ArgumentMatchers.same; + +import org.apache.ignite.internal.schema.marshaller.reflection.ReflectionMarshallerFactory; +import org.apache.ignite.internal.schema.row.Row; +import org.apache.ignite.table.KeyValueView; +import org.apache.ignite.table.RecordView; +import org.apache.ignite.table.Table; + +class AssertMarshaller { + private AssertMarshaller() {} + + private static final MarshallerFactory factory = new ReflectionMarshallerFactory(); + + static <T> void assertMarshaller(T expected) { + RecordMarshaller<T> m = (RecordMarshaller<T>) factory.create(schema, expected.getClass()); + Row row = Row.wrapBinaryRow(schema, m.marshal(expected)); + T actual = m.unmarshal(row); + + assertThat(actual, not(same(expected))); + assertThat(actual, equalTo(expected)); + } + + static <K, V> void assertMarshaller(K expectedKey, V expectedVal) { + KvMarshaller<K, V> m = (KvMarshaller<K, V>) factory.create(schema, expectedKey.getClass(), expectedVal.getClass()); + Row row = Row.wrapBinaryRow(schema, m.marshal(expectedKey, expectedVal)); + K actualKey = m.unmarshalKey(row); + V actualVal = m.unmarshalValue(row); + + assertThat(actualKey, not(same(expectedKey))); + assertThat(actualKey, equalTo(expectedKey)); + + assertThat(actualVal, not(same(expectedVal))); + assertThat(actualVal, equalTo(expectedVal)); + } + + static <T, E extends Throwable> void assertMarshallerThrows(Class<E> expectedType, String msgSubstring, T expected) { + var ex = assertThrows(expectedType, () -> assertMarshaller(expected)); + assertThat(ex.getMessage(), containsString(msgSubstring)); Review Comment: `IgniteTestUtils.assertThrows` could be used here and below: ```suggestion assertThrows(expectedType, () -> assertMarshaller(expected), msgSubstring); ``` ########## modules/java-records-tests/src/integrationTest/java/org/apache/ignite/internal/schema/marshaller/ItTableViewTest.java: ########## @@ -0,0 +1,165 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.schema.marshaller; + +import static org.apache.ignite.internal.lang.IgniteStringFormatter.format; +import static org.apache.ignite.internal.schema.marshaller.AssertMarshaller.assertView; +import static org.apache.ignite.internal.schema.marshaller.AssertMarshaller.assertViewThrows; +import static org.junit.jupiter.api.Named.named; +import static org.junit.jupiter.params.provider.Arguments.arguments; + +import java.util.stream.Stream; +import org.apache.ignite.client.IgniteClient; +import org.apache.ignite.internal.ClusterPerClassIntegrationTest; +import org.apache.ignite.internal.schema.marshaller.Records.ComponentsExact; +import org.apache.ignite.internal.schema.marshaller.Records.ComponentsNarrow; +import org.apache.ignite.internal.schema.marshaller.Records.ComponentsReordered; +import org.apache.ignite.internal.schema.marshaller.Records.ComponentsWide; +import org.apache.ignite.internal.schema.marshaller.Records.ComponentsWrongTypes; +import org.apache.ignite.internal.schema.marshaller.Records.NotAnnotatedNotMapped; +import org.apache.ignite.internal.util.IgniteUtils; +import org.apache.ignite.lang.MarshallerException; +import org.apache.ignite.table.Table; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +/** + * Ensures that records and classes behave the same way. + */ +class ItTableViewTest extends ClusterPerClassIntegrationTest { + private static final String TBL = "TBL"; + private static IgniteClient CLIENT; + private static Table TABLE_EMBEDDED; + private static Table TABLE_CLIENT; + + private static Stream<Arguments> tableImpls() { + return Stream.of( + arguments(named("embedded", TABLE_EMBEDDED)), + arguments(named("client", TABLE_CLIENT)) + ); + } + + @BeforeAll + static void beforeAll() { + CLIENT = IgniteClient.builder() + .addresses("localhost:10800") + .build(); + + sql(format(Records.SQL_PATTERN, TBL)); + + TABLE_EMBEDDED = CLUSTER.aliveNode().tables().table(TBL); + TABLE_CLIENT = CLIENT.tables().table(TBL); Review Comment: We need to find a way to synchronize access - a table created from one client (embedded in this case) doesn't guaranteed to be available on the other client immediately. Simplest way could be to subclass this test so that each class will use the same client. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
