Skip to content

Commit

Permalink
IGNITE-15924 Thin client cache for OptimizedMarshaller class names (a…
Browse files Browse the repository at this point in the history
  • Loading branch information
nizhikov committed Nov 22, 2021
1 parent cca909c commit 620ee3f
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,9 @@ public ClientMarshallerContext() {
catch (ClientException e) {
throw new IgniteCheckedException(e);
}

if (clsName != null)
cache.putIfAbsent(typeId, clsName);
}

if (clsName == null)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* 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.client.thin;

import java.time.LocalDateTime;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
import java.util.function.Function;
import org.apache.ignite.Ignite;
import org.apache.ignite.client.ClientException;
import org.apache.ignite.client.Config;
import org.apache.ignite.client.IgniteClient;
import org.apache.ignite.configuration.ClientConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
import org.junit.Test;

/** */
public class OptimizedMarshallerClassesCachedTest extends GridCommonAbstractTest {
/** */
private final AtomicInteger cnt = new AtomicInteger();

/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
return super.getConfiguration(igniteInstanceName);
}

/** Test check that meta for classes serialized by {@link OptimizedMarshaller} are cached on client. */
@Test
public void testLocalDateTimeMetaCached() throws Exception {
try (Ignite srv = startGrid(0)) {
srv.getOrCreateCache(Config.DEFAULT_CACHE_NAME).put(1, LocalDateTime.now());

IgniteClient cli = new TcpIgniteClient((cfg0, hnd) -> new TcpClientChannel(cfg0, hnd) {
@Override public <T> T service(
ClientOperation op,
Consumer<PayloadOutputChannel> payloadWriter,
Function<PayloadInputChannel, T> payloadReader
) throws ClientException {
if (op == ClientOperation.GET_BINARY_TYPE_NAME)
cnt.incrementAndGet();

return super.service(op, payloadWriter, payloadReader);
}

@Override public <T> CompletableFuture<T> serviceAsync(
ClientOperation op,
Consumer<PayloadOutputChannel> payloadWriter,
Function<PayloadInputChannel, T> payloadReader
) {
if (op == ClientOperation.GET_BINARY_TYPE_NAME)
cnt.incrementAndGet();

return super.serviceAsync(op, payloadWriter, payloadReader);
}
}, new ClientConfiguration().setAddresses(Config.SERVER));

try {
cli.cache(Config.DEFAULT_CACHE_NAME).get(1);
cli.cache(Config.DEFAULT_CACHE_NAME).get(1);
}
finally {
cli.close();
}

assertEquals(1, cnt.get());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.ignite.internal.client.thin.ClusterApiTest;
import org.apache.ignite.internal.client.thin.ClusterGroupTest;
import org.apache.ignite.internal.client.thin.ComputeTaskTest;
import org.apache.ignite.internal.client.thin.OptimizedMarshallerClassesCachedTest;
import org.apache.ignite.internal.client.thin.ReliableChannelTest;
import org.apache.ignite.internal.client.thin.ServicesTest;
import org.apache.ignite.internal.client.thin.ThinClientPartitionAwarenessDiscoveryTest;
Expand Down Expand Up @@ -64,7 +65,8 @@
ThinClientPartitionAwarenessDiscoveryTest.class,
ReliableChannelTest.class,
CacheAsyncTest.class,
TimeoutTest.class
TimeoutTest.class,
OptimizedMarshallerClassesCachedTest.class,
})
public class ClientTestSuite {
// No-op.
Expand Down

0 comments on commit 620ee3f

Please sign in to comment.