-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration test for http protocol (client)
- Loading branch information
Showing
7 changed files
with
139 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
thrifty-test-server/src/main/java/com/microsoft/thrifty/testing/HttpServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.microsoft.thrifty.testing; | ||
|
||
import org.apache.catalina.LifecycleException; | ||
import org.apache.catalina.core.StandardContext; | ||
import org.apache.catalina.startup.Tomcat; | ||
|
||
import static com.microsoft.thrifty.testing.TestServer.getProtocolFactory; | ||
|
||
public class HttpServer implements TestServerInterface { | ||
private Tomcat tomcat; | ||
|
||
@Override | ||
public void run(ServerProtocol protocol, ServerTransport transport) { | ||
if (transport != ServerTransport.HTTP) { | ||
throw new IllegalArgumentException("only http transport supported"); | ||
} | ||
this.tomcat = new Tomcat(); | ||
tomcat.setBaseDir(System.getProperty("user.dir") + "\\build"); | ||
tomcat.setPort(0); | ||
tomcat.getHost().setAutoDeploy(false); | ||
|
||
String contextPath = "/test"; | ||
StandardContext context = new StandardContext(); | ||
context.setPath(contextPath); | ||
context.addLifecycleListener(new Tomcat.FixContextListener()); | ||
tomcat.getHost().addChild(context); | ||
tomcat.addServlet(contextPath, "testServlet", new TestServlet(getProtocolFactory(protocol))); | ||
context.addServletMappingDecoded("/service", "testServlet"); | ||
try { | ||
tomcat.start(); | ||
} catch (LifecycleException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public int port() { | ||
return tomcat.getConnector().getLocalPort(); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
try { | ||
tomcat.stop(); | ||
} catch (LifecycleException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
thrifty-test-server/src/main/java/com/microsoft/thrifty/testing/TestServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* 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 com.microsoft.thrifty.testing; | ||
|
||
import com.microsoft.thrifty.test.gen.ThriftTest; | ||
import org.apache.thrift.TProcessor; | ||
import org.apache.thrift.protocol.TProtocolFactory; | ||
import org.apache.thrift.server.TExtensibleServlet; | ||
|
||
@SuppressWarnings("serial") | ||
public class TestServlet extends TExtensibleServlet { | ||
private final TProtocolFactory protocolFactory; | ||
|
||
public TestServlet(TProtocolFactory protocolFactory) { | ||
this.protocolFactory = protocolFactory; | ||
} | ||
|
||
@Override | ||
protected TProtocolFactory getInProtocolFactory() { | ||
return protocolFactory; | ||
} | ||
|
||
@Override | ||
protected TProtocolFactory getOutProtocolFactory() { | ||
return protocolFactory; | ||
} | ||
|
||
@SuppressWarnings({"rawtypes", "unchecked"}) | ||
@Override | ||
protected TProcessor getProcessor() { | ||
ThriftTestHandler handler = new ThriftTestHandler(System.out); | ||
return new ThriftTest.Processor<>(handler); | ||
} | ||
} |