greyp9 commented on code in PR #6994: URL: https://github.com/apache/nifi/pull/6994#discussion_r1123578607
########## nifi-nar-bundles/nifi-standard-services/nifi-distributed-cache-services-bundle/nifi-distributed-cache-server/src/test/java/org/apache/nifi/distributed/cache/server/map/TestMapCacheClient.java: ########## @@ -0,0 +1,146 @@ +/* + * 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.nifi.distributed.cache.server.map; + +import org.apache.commons.lang3.SerializationException; +import org.apache.nifi.components.PropertyDescriptor; +import org.apache.nifi.distributed.cache.client.DistributedMapCacheClientService; +import org.apache.nifi.distributed.cache.client.Serializer; +import org.apache.nifi.distributed.cache.operations.MapOperation; +import org.apache.nifi.distributed.cache.protocol.ProtocolVersion; +import org.apache.nifi.distributed.cache.server.EvictionPolicy; +import org.apache.nifi.distributed.cache.server.codec.CacheOperationResultEncoder; +import org.apache.nifi.distributed.cache.server.codec.CacheVersionRequestHandler; +import org.apache.nifi.distributed.cache.server.codec.CacheVersionResponseEncoder; +import org.apache.nifi.distributed.cache.server.codec.MapCacheRequestDecoder; +import org.apache.nifi.distributed.cache.server.codec.MapCacheRequestHandler; +import org.apache.nifi.distributed.cache.server.codec.MapRemoveResponseEncoder; +import org.apache.nifi.distributed.cache.server.codec.MapSizeResponseEncoder; +import org.apache.nifi.distributed.cache.server.codec.MapValueResponseEncoder; +import org.apache.nifi.event.transport.EventServer; +import org.apache.nifi.event.transport.configuration.ShutdownQuietPeriod; +import org.apache.nifi.event.transport.configuration.TransportProtocol; +import org.apache.nifi.event.transport.netty.NettyEventServerFactory; +import org.apache.nifi.logging.ComponentLog; +import org.apache.nifi.processor.Processor; +import org.apache.nifi.remote.StandardVersionNegotiator; +import org.apache.nifi.remote.VersionNegotiator; +import org.apache.nifi.remote.io.socket.NetworkUtils; +import org.apache.nifi.reporting.InitializationException; +import org.apache.nifi.util.MockConfigurationContext; +import org.apache.nifi.util.MockControllerServiceInitializationContext; +import org.apache.nifi.util.TestRunner; +import org.apache.nifi.util.TestRunners; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +import java.io.IOException; +import java.io.OutputStream; +import java.net.InetAddress; +import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertThrows; + +public class TestMapCacheClient { + private int port; + private EventServer server; + private final Serializer<String> stringSerializer = new StringSerializer(); + + @BeforeEach + public void setRunner() { + final TestRunner runner = TestRunners.newTestRunner(Mockito.mock(Processor.class)); + port = NetworkUtils.getAvailableTcpPort(); + + final NettyEventServerFactory serverFactory = new NettyEventServerFactory( + InetAddress.getLoopbackAddress(), port, TransportProtocol.TCP); + serverFactory.setShutdownQuietPeriod(ShutdownQuietPeriod.QUICK.getDuration()); + serverFactory.setShutdownTimeout(ShutdownQuietPeriod.QUICK.getDuration()); + final ComponentLog log = runner.getLogger(); + final VersionNegotiator versionNegotiator = new StandardVersionNegotiator( + ProtocolVersion.V3.value(), ProtocolVersion.V2.value(), ProtocolVersion.V1.value()); + + final MapCache mapCache = new SimpleMapCache("serviceIdentifier", 64, EvictionPolicy.FIFO) { + // override a service function that will cause client network timeout to fire + @Override + public MapPutResult put(ByteBuffer key, ByteBuffer value) throws IOException { + try { + Thread.sleep(3000L); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + return super.put(key, value); Review Comment: New approach; got rid of the override altogether. -- 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: issues-unsubscr...@nifi.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org