jduo commented on a change in pull request #8583: URL: https://github.com/apache/arrow/pull/8583#discussion_r517166976
########## File path: java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestServerSessionHandling.java ########## @@ -0,0 +1,208 @@ +/* + * 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.arrow.flight; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.arrow.flight.grpc.RequestContextAdapter; +import org.junit.Test; + +import com.google.common.collect.ImmutableList; + +/** + * Tests for ServerSessionHandler and ServerSessionMiddleware. + */ +public class TestServerSessionHandling { + private static final String SESSION_HEADER_KEY = "Session"; + private static final String SET_SESSION_HEADER_KEY = "Set-Session"; + private static final String TEST_SESSION = "name=test-session;id=session-id;max-age=100"; + private static final List<String> VALID_PROPERTY_KEYS = ImmutableList.of( + "name", + "id", + "max-age" + ); + + private class SimpleServerSessionHandler implements ServerSessionHandler { + private String session; + + SimpleServerSessionHandler() { + this.session = null; + } + + @Override + public String beginSession(CallHeaders headers) { + session = TEST_SESSION; + return session; + } + + @Override + public String getSession(CallHeaders headers) { + // No session has been set yet + if (session == null) { + return null; + } + + // Expected session header but none is found + if (!headers.containsKey(SESSION_HEADER_KEY)) { Review comment: This code to parse the header should not be done by the implementation of the interface since we are generating and transmitting this header in the Flight layer (so this logic isn't FlightProducer-implementation-specific). ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected]
