Upgrading dependency to Thrift 0.12.0
This commit is contained in:
parent
3e4590dcc0
commit
356978cb42
1302 changed files with 101701 additions and 26784 deletions
2
vendor/git.apache.org/thrift.git/lib/java/test/org/apache/thrift/Fixtures.java
generated
vendored
2
vendor/git.apache.org/thrift.git/lib/java/test/org/apache/thrift/Fixtures.java
generated
vendored
|
@ -277,7 +277,7 @@ public class Fixtures {
|
|||
nesting = new Nesting(bonk, oneOfEach);
|
||||
|
||||
holyMoley = new HolyMoley();
|
||||
ArrayList big = new ArrayList<OneOfEach>();
|
||||
List<OneOfEach> big = new ArrayList<OneOfEach>();
|
||||
big.add(new OneOfEach(oneOfEach));
|
||||
big.add(nesting.my_ooe);
|
||||
holyMoley.setBig(big);
|
||||
|
|
34
vendor/git.apache.org/thrift.git/lib/java/test/org/apache/thrift/TestDeepCopy.java
generated
vendored
Normal file
34
vendor/git.apache.org/thrift.git/lib/java/test/org/apache/thrift/TestDeepCopy.java
generated
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
package org.apache.thrift;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import thrift.test.DeepCopyBar;
|
||||
import thrift.test.DeepCopyFoo;
|
||||
|
||||
public class TestDeepCopy extends TestCase {
|
||||
|
||||
public void testDeepCopy() throws Exception {
|
||||
final DeepCopyFoo foo = new DeepCopyFoo();
|
||||
|
||||
foo.addToL(new DeepCopyBar());
|
||||
foo.addToS(new DeepCopyBar());
|
||||
foo.putToM("test 3", new DeepCopyBar());
|
||||
|
||||
foo.addToLi(new thrift.test.Object());
|
||||
foo.addToSi(new thrift.test.Object());
|
||||
foo.putToMi("test 3", new thrift.test.Object());
|
||||
|
||||
foo.setBar(new DeepCopyBar());
|
||||
|
||||
final DeepCopyFoo deepCopyFoo = foo.deepCopy();
|
||||
|
||||
assertNotSame(foo.getBar(), deepCopyFoo.getBar());
|
||||
|
||||
assertNotSame(foo.getL().get(0), deepCopyFoo.getL().get(0));
|
||||
assertNotSame(foo.getS().toArray(new DeepCopyBar[0])[0], deepCopyFoo.getS().toArray(new DeepCopyBar[0])[0]);
|
||||
assertNotSame(foo.getM().get("test 3"), deepCopyFoo.getM().get("test 3"));
|
||||
|
||||
assertNotSame(foo.getLi().get(0), deepCopyFoo.getLi().get(0));
|
||||
assertNotSame(foo.getSi().toArray(new thrift.test.Object[0])[0], deepCopyFoo.getSi().toArray(new thrift.test.Object[0])[0]);
|
||||
assertNotSame(foo.getMi().get("test 3"), deepCopyFoo.getMi().get("test 3"));
|
||||
}
|
||||
}
|
81
vendor/git.apache.org/thrift.git/lib/java/test/org/apache/thrift/TestEnumContainers.java
generated
vendored
Normal file
81
vendor/git.apache.org/thrift.git/lib/java/test/org/apache/thrift/TestEnumContainers.java
generated
vendored
Normal file
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* 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.thrift;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import thrift.test.enumcontainers.EnumContainersTestConstants;
|
||||
import thrift.test.enumcontainers.GodBean;
|
||||
import thrift.test.enumcontainers.GreekGodGoddess;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class TestEnumContainers extends TestCase {
|
||||
|
||||
public void testEnumContainers() throws Exception {
|
||||
final GodBean b1 = new GodBean();
|
||||
b1.addToGoddess(GreekGodGoddess.HERA);
|
||||
b1.getGoddess().add(GreekGodGoddess.APHRODITE);
|
||||
b1.putToPower(GreekGodGoddess.ZEUS, 1000);
|
||||
b1.getPower().put(GreekGodGoddess.HERA, 333);
|
||||
b1.putToByAlias("Mr. Z", GreekGodGoddess.ZEUS);
|
||||
b1.addToImages("Baths of Aphrodite 01.jpeg");
|
||||
|
||||
final GodBean b2 = new GodBean(b1);
|
||||
|
||||
final GodBean b3 = new GodBean();
|
||||
{
|
||||
final TSerializer serializer = new TSerializer();
|
||||
final TDeserializer deserializer = new TDeserializer();
|
||||
|
||||
final byte[] bytes = serializer.serialize(b1);
|
||||
deserializer.deserialize(b3, bytes);
|
||||
}
|
||||
|
||||
assertTrue(b1.getGoddess() != b2.getGoddess());
|
||||
assertTrue(b1.getPower() != b2.getPower());
|
||||
|
||||
assertTrue(b1.getGoddess() != b3.getGoddess());
|
||||
assertTrue(b1.getPower() != b3.getPower());
|
||||
|
||||
for (GodBean each : new GodBean[]{b1, b2, b3}) {
|
||||
assertTrue(each.getGoddess().contains(GreekGodGoddess.HERA));
|
||||
assertFalse(each.getGoddess().contains(GreekGodGoddess.POSEIDON));
|
||||
assertTrue(each.getGoddess() instanceof EnumSet);
|
||||
|
||||
assertEquals(Integer.valueOf(1000), each.getPower().get(GreekGodGoddess.ZEUS));
|
||||
assertEquals(Integer.valueOf(333), each.getPower().get(GreekGodGoddess.HERA));
|
||||
assertTrue(each.getPower() instanceof EnumMap);
|
||||
|
||||
assertTrue(each.getByAlias() instanceof HashMap);
|
||||
assertTrue(each.getImages() instanceof HashSet);
|
||||
}
|
||||
}
|
||||
|
||||
public void testEnumConstants() {
|
||||
assertEquals("lightning bolt", EnumContainersTestConstants.ATTRIBUTES.get(GreekGodGoddess.ZEUS));
|
||||
assertTrue(EnumContainersTestConstants.ATTRIBUTES instanceof EnumMap);
|
||||
|
||||
assertTrue(EnumContainersTestConstants.BEAUTY.contains(GreekGodGoddess.APHRODITE));
|
||||
assertTrue(EnumContainersTestConstants.BEAUTY instanceof EnumSet);
|
||||
}
|
||||
}
|
86
vendor/git.apache.org/thrift.git/lib/java/test/org/apache/thrift/TestMultiplexedProcessor.java
generated
vendored
Normal file
86
vendor/git.apache.org/thrift.git/lib/java/test/org/apache/thrift/TestMultiplexedProcessor.java
generated
vendored
Normal file
|
@ -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.thrift;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.apache.thrift.protocol.TMessage;
|
||||
import org.apache.thrift.protocol.TMessageType;
|
||||
import org.apache.thrift.protocol.TProtocol;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestMultiplexedProcessor {
|
||||
private TMultiplexedProcessor mp;
|
||||
private TProtocol iprot;
|
||||
private TProtocol oprot;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
mp = new TMultiplexedProcessor();
|
||||
iprot = mock(TProtocol.class);
|
||||
oprot = mock(TProtocol.class);
|
||||
}
|
||||
|
||||
@Test(expected = TException.class)
|
||||
public void testWrongMessageType() throws TException {
|
||||
when (iprot.readMessageBegin()).thenReturn(new TMessage("service:func", TMessageType.REPLY, 42));
|
||||
mp.process(iprot, oprot);
|
||||
}
|
||||
|
||||
@Test(expected = TException.class)
|
||||
public void testNoSuchService() throws TException {
|
||||
when(iprot.readMessageBegin()).thenReturn(new TMessage("service:func", TMessageType.CALL, 42));
|
||||
|
||||
mp.process(iprot, oprot);
|
||||
}
|
||||
|
||||
static class StubProcessor implements TProcessor {
|
||||
@Override
|
||||
public boolean process(TProtocol in, TProtocol out) throws TException {
|
||||
TMessage msg = in.readMessageBegin();
|
||||
if (!"func".equals(msg.name) || msg.type!=TMessageType.CALL || msg.seqid!=42) {
|
||||
throw new TException("incorrect parameters");
|
||||
}
|
||||
out.writeMessageBegin(new TMessage("func", TMessageType.REPLY, 42));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExistingService() throws TException {
|
||||
when(iprot.readMessageBegin()).thenReturn(new TMessage("service:func", TMessageType.CALL, 42));
|
||||
mp.registerProcessor("service", new StubProcessor());
|
||||
mp.process(iprot, oprot);
|
||||
verify(oprot).writeMessageBegin(any(TMessage.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultService() throws TException {
|
||||
when(iprot.readMessageBegin()).thenReturn(new TMessage("func", TMessageType.CALL, 42));
|
||||
mp.registerDefault(new StubProcessor());
|
||||
mp.process(iprot, oprot);
|
||||
verify(oprot).writeMessageBegin(any(TMessage.class));
|
||||
}
|
||||
|
||||
}
|
179
vendor/git.apache.org/thrift.git/lib/java/test/org/apache/thrift/TestRenderedDoubleConstants.java
generated
vendored
Normal file
179
vendor/git.apache.org/thrift.git/lib/java/test/org/apache/thrift/TestRenderedDoubleConstants.java
generated
vendored
Normal file
|
@ -0,0 +1,179 @@
|
|||
/*
|
||||
* 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.thrift;
|
||||
|
||||
import java.util.List;
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Test;
|
||||
import thrift.test.DoubleConstantsTestConstants;
|
||||
|
||||
public class TestRenderedDoubleConstants extends TestCase {
|
||||
private static final double EPSILON = 0.0000001;
|
||||
private static final String ASSERTION_MESSAGE_FOR_RENDERED_DOUBLE_CONSTANTS_TEST =
|
||||
"failed to verify a double constant generated by Thrift (expected = %f, got = %f)";
|
||||
private static final String ASSERTION_MESSAGE_FOR_RENDERED_DOUBLE_LIST_TEST =
|
||||
"failed to verify a list item by Thrift (expected = %f, got = %f)";
|
||||
private static final String ASSERTION_MESSAGE_FOR_TYPE_CHECKS =
|
||||
"the rendered variable with name %s is not of double type";
|
||||
|
||||
// to make sure lists containing doubles are generated correctly
|
||||
public void testRenderedDoubleList() throws Exception {
|
||||
final double[] EXPECTED_LIST =
|
||||
{1d,-100d,100d,9223372036854775807d,-9223372036854775807d,3.14159265359,1000000.1,-1000000.1,1.7e+308,
|
||||
-1.7e+308,9223372036854775816.43,-9223372036854775816.43};
|
||||
assertEquals(EXPECTED_LIST.length, DoubleConstantsTestConstants.DOUBLE_LIST_TEST.size());
|
||||
for (int i = 0; i < EXPECTED_LIST.length; ++i) {
|
||||
assertEquals(
|
||||
String.format(
|
||||
ASSERTION_MESSAGE_FOR_RENDERED_DOUBLE_LIST_TEST,
|
||||
EXPECTED_LIST[i],
|
||||
DoubleConstantsTestConstants.DOUBLE_LIST_TEST.get(i)),
|
||||
EXPECTED_LIST[i], DoubleConstantsTestConstants.DOUBLE_LIST_TEST.get(i), EPSILON);
|
||||
}
|
||||
}
|
||||
|
||||
// to make sure the variables inside Thrift files are generated correctly
|
||||
public void testRenderedDoubleConstants() throws Exception {
|
||||
final double EXPECTED_DOUBLE_ASSIGNED_TO_INT_CONSTANT = 1.0;
|
||||
final double EXPECTED_DOUBLE_ASSIGNED_TO_NEGATIVE_INT_CONSTANT = -100.0;
|
||||
final double EXPECTED_DOUBLE_ASSIGNED_TO_LARGEST_INT_CONSTANT = 9223372036854775807.0;
|
||||
final double EXPECTED_DOUBLE_ASSIGNED_TO_SMALLEST_INT_CONSTANT = -9223372036854775807.0;
|
||||
final double EXPECTED_DOUBLE_ASSIGNED_TO_DOUBLE_WITH_MANY_DECIMALS = 3.14159265359;
|
||||
final double EXPECTED_DOUBLE_ASSIGNED_TO_FRACTIONAL_DOUBLE = 1000000.1;
|
||||
final double EXPECTED_DOUBLE_ASSIGNED_TO_NEGATIVE_FRACTIONAL_DOUBLE = -1000000.1;
|
||||
final double EXPECTED_DOUBLE_ASSIGNED_TO_LARGE_DOUBLE = 1.7e+308;
|
||||
final double EXPECTED_DOUBLE_ASSIGNED_TO_LARGE_FRACTIONAL_DOUBLE = 9223372036854775816.43;
|
||||
final double EXPECTED_DOUBLE_ASSIGNED_TO_SMALL_DOUBLE = -1.7e+308;
|
||||
final double EXPECTED_DOUBLE_ASSIGNED_TO_NEGATIVE_BUT_LARGE_FRACTIONAL_DOUBLE = -9223372036854775816.43;
|
||||
assertEquals(
|
||||
String.format(
|
||||
ASSERTION_MESSAGE_FOR_RENDERED_DOUBLE_CONSTANTS_TEST,
|
||||
EXPECTED_DOUBLE_ASSIGNED_TO_INT_CONSTANT,
|
||||
DoubleConstantsTestConstants.DOUBLE_ASSIGNED_TO_INT_CONSTANT_TEST),
|
||||
EXPECTED_DOUBLE_ASSIGNED_TO_INT_CONSTANT,
|
||||
DoubleConstantsTestConstants.DOUBLE_ASSIGNED_TO_INT_CONSTANT_TEST, EPSILON);
|
||||
assertEquals(
|
||||
String.format(
|
||||
ASSERTION_MESSAGE_FOR_RENDERED_DOUBLE_CONSTANTS_TEST,
|
||||
EXPECTED_DOUBLE_ASSIGNED_TO_NEGATIVE_INT_CONSTANT,
|
||||
DoubleConstantsTestConstants.DOUBLE_ASSIGNED_TO_NEGATIVE_INT_CONSTANT_TEST),
|
||||
EXPECTED_DOUBLE_ASSIGNED_TO_NEGATIVE_INT_CONSTANT,
|
||||
DoubleConstantsTestConstants.DOUBLE_ASSIGNED_TO_NEGATIVE_INT_CONSTANT_TEST, EPSILON);
|
||||
assertEquals(
|
||||
String.format(
|
||||
ASSERTION_MESSAGE_FOR_RENDERED_DOUBLE_CONSTANTS_TEST,
|
||||
EXPECTED_DOUBLE_ASSIGNED_TO_LARGEST_INT_CONSTANT,
|
||||
DoubleConstantsTestConstants.DOUBLE_ASSIGNED_TO_LARGEST_INT_CONSTANT_TEST),
|
||||
EXPECTED_DOUBLE_ASSIGNED_TO_LARGEST_INT_CONSTANT,
|
||||
DoubleConstantsTestConstants.DOUBLE_ASSIGNED_TO_LARGEST_INT_CONSTANT_TEST, EPSILON);
|
||||
assertEquals(
|
||||
String.format(
|
||||
ASSERTION_MESSAGE_FOR_RENDERED_DOUBLE_CONSTANTS_TEST,
|
||||
EXPECTED_DOUBLE_ASSIGNED_TO_SMALLEST_INT_CONSTANT,
|
||||
DoubleConstantsTestConstants.DOUBLE_ASSIGNED_TO_SMALLEST_INT_CONSTANT_TEST),
|
||||
EXPECTED_DOUBLE_ASSIGNED_TO_SMALLEST_INT_CONSTANT,
|
||||
DoubleConstantsTestConstants.DOUBLE_ASSIGNED_TO_SMALLEST_INT_CONSTANT_TEST, EPSILON);
|
||||
assertEquals(
|
||||
String.format(
|
||||
ASSERTION_MESSAGE_FOR_RENDERED_DOUBLE_CONSTANTS_TEST,
|
||||
EXPECTED_DOUBLE_ASSIGNED_TO_DOUBLE_WITH_MANY_DECIMALS,
|
||||
DoubleConstantsTestConstants.DOUBLE_ASSIGNED_TO_DOUBLE_WITH_MANY_DECIMALS_TEST),
|
||||
EXPECTED_DOUBLE_ASSIGNED_TO_DOUBLE_WITH_MANY_DECIMALS,
|
||||
DoubleConstantsTestConstants.DOUBLE_ASSIGNED_TO_DOUBLE_WITH_MANY_DECIMALS_TEST, EPSILON);
|
||||
assertEquals(
|
||||
String.format(
|
||||
ASSERTION_MESSAGE_FOR_RENDERED_DOUBLE_CONSTANTS_TEST,
|
||||
EXPECTED_DOUBLE_ASSIGNED_TO_FRACTIONAL_DOUBLE,
|
||||
DoubleConstantsTestConstants.DOUBLE_ASSIGNED_TO_FRACTIONAL_DOUBLE_TEST),
|
||||
EXPECTED_DOUBLE_ASSIGNED_TO_FRACTIONAL_DOUBLE,
|
||||
DoubleConstantsTestConstants.DOUBLE_ASSIGNED_TO_FRACTIONAL_DOUBLE_TEST, EPSILON);
|
||||
assertEquals(
|
||||
String.format(
|
||||
ASSERTION_MESSAGE_FOR_RENDERED_DOUBLE_CONSTANTS_TEST,
|
||||
EXPECTED_DOUBLE_ASSIGNED_TO_NEGATIVE_FRACTIONAL_DOUBLE,
|
||||
DoubleConstantsTestConstants.DOUBLE_ASSIGNED_TO_NEGATIVE_FRACTIONAL_DOUBLE_TEST),
|
||||
EXPECTED_DOUBLE_ASSIGNED_TO_NEGATIVE_FRACTIONAL_DOUBLE,
|
||||
DoubleConstantsTestConstants.DOUBLE_ASSIGNED_TO_NEGATIVE_FRACTIONAL_DOUBLE_TEST, EPSILON);
|
||||
assertEquals(
|
||||
String.format(
|
||||
ASSERTION_MESSAGE_FOR_RENDERED_DOUBLE_CONSTANTS_TEST,
|
||||
EXPECTED_DOUBLE_ASSIGNED_TO_LARGE_DOUBLE,
|
||||
DoubleConstantsTestConstants.DOUBLE_ASSIGNED_TO_LARGE_DOUBLE_TEST),
|
||||
EXPECTED_DOUBLE_ASSIGNED_TO_LARGE_DOUBLE,
|
||||
DoubleConstantsTestConstants.DOUBLE_ASSIGNED_TO_LARGE_DOUBLE_TEST, EPSILON);
|
||||
assertEquals(
|
||||
String.format(
|
||||
ASSERTION_MESSAGE_FOR_RENDERED_DOUBLE_CONSTANTS_TEST,
|
||||
EXPECTED_DOUBLE_ASSIGNED_TO_LARGE_FRACTIONAL_DOUBLE,
|
||||
DoubleConstantsTestConstants.DOUBLE_ASSIGNED_TO_LARGE_FRACTIONAL_DOUBLE_TEST),
|
||||
EXPECTED_DOUBLE_ASSIGNED_TO_LARGE_FRACTIONAL_DOUBLE,
|
||||
DoubleConstantsTestConstants.DOUBLE_ASSIGNED_TO_LARGE_FRACTIONAL_DOUBLE_TEST, EPSILON);
|
||||
assertEquals(
|
||||
String.format(
|
||||
ASSERTION_MESSAGE_FOR_RENDERED_DOUBLE_CONSTANTS_TEST,
|
||||
EXPECTED_DOUBLE_ASSIGNED_TO_SMALL_DOUBLE,
|
||||
DoubleConstantsTestConstants.DOUBLE_ASSIGNED_TO_SMALL_DOUBLE_TEST),
|
||||
EXPECTED_DOUBLE_ASSIGNED_TO_SMALL_DOUBLE,
|
||||
DoubleConstantsTestConstants.DOUBLE_ASSIGNED_TO_SMALL_DOUBLE_TEST, EPSILON);
|
||||
assertEquals(
|
||||
String.format(
|
||||
ASSERTION_MESSAGE_FOR_RENDERED_DOUBLE_CONSTANTS_TEST,
|
||||
EXPECTED_DOUBLE_ASSIGNED_TO_NEGATIVE_BUT_LARGE_FRACTIONAL_DOUBLE,
|
||||
DoubleConstantsTestConstants.DOUBLE_ASSIGNED_TO_NEGATIVE_BUT_LARGE_FRACTIONAL_DOUBLE_TEST),
|
||||
EXPECTED_DOUBLE_ASSIGNED_TO_NEGATIVE_BUT_LARGE_FRACTIONAL_DOUBLE,
|
||||
DoubleConstantsTestConstants.DOUBLE_ASSIGNED_TO_NEGATIVE_BUT_LARGE_FRACTIONAL_DOUBLE_TEST, EPSILON);
|
||||
assertTrue(
|
||||
String.format(ASSERTION_MESSAGE_FOR_TYPE_CHECKS, "DOUBLE_ASSIGNED_TO_INT_CONSTANT_TEST"),
|
||||
Double.class.isInstance(DoubleConstantsTestConstants.DOUBLE_ASSIGNED_TO_INT_CONSTANT_TEST));
|
||||
assertTrue(
|
||||
String.format(ASSERTION_MESSAGE_FOR_TYPE_CHECKS, "DOUBLE_ASSIGNED_TO_NEGATIVE_INT_CONSTANT_TEST"),
|
||||
Double.class.isInstance(DoubleConstantsTestConstants.DOUBLE_ASSIGNED_TO_NEGATIVE_INT_CONSTANT_TEST));
|
||||
assertTrue(
|
||||
String.format(ASSERTION_MESSAGE_FOR_TYPE_CHECKS, "DOUBLE_ASSIGNED_TO_LARGEST_INT_CONSTANT_TEST"),
|
||||
Double.class.isInstance(DoubleConstantsTestConstants.DOUBLE_ASSIGNED_TO_LARGEST_INT_CONSTANT_TEST));
|
||||
assertTrue(
|
||||
String.format(ASSERTION_MESSAGE_FOR_TYPE_CHECKS, "DOUBLE_ASSIGNED_TO_SMALLEST_INT_CONSTANT_TEST"),
|
||||
Double.class.isInstance(DoubleConstantsTestConstants.DOUBLE_ASSIGNED_TO_SMALLEST_INT_CONSTANT_TEST));
|
||||
assertTrue(
|
||||
String.format(ASSERTION_MESSAGE_FOR_TYPE_CHECKS, "DOUBLE_ASSIGNED_TO_DOUBLE_WITH_MANY_DECIMALS_TEST"),
|
||||
Double.class.isInstance(DoubleConstantsTestConstants.DOUBLE_ASSIGNED_TO_DOUBLE_WITH_MANY_DECIMALS_TEST));
|
||||
assertTrue(
|
||||
String.format(ASSERTION_MESSAGE_FOR_TYPE_CHECKS, "DOUBLE_ASSIGNED_TO_FRACTIONAL_DOUBLE_TEST"),
|
||||
Double.class.isInstance(DoubleConstantsTestConstants.DOUBLE_ASSIGNED_TO_FRACTIONAL_DOUBLE_TEST));
|
||||
assertTrue(
|
||||
String.format(ASSERTION_MESSAGE_FOR_TYPE_CHECKS, "DOUBLE_ASSIGNED_TO_NEGATIVE_FRACTIONAL_DOUBLE_TEST"),
|
||||
Double.class.isInstance(DoubleConstantsTestConstants.DOUBLE_ASSIGNED_TO_NEGATIVE_FRACTIONAL_DOUBLE_TEST));
|
||||
//assertTrue(
|
||||
// String.format(ASSERTION_MESSAGE_FOR_TYPE_CHECKS, "DOUBLE_ASSIGNED_TO_LARGE_DOUBLE_TEST"),
|
||||
// Double.class.isInstance(DoubleConstantsTestConstants.DOUBLE_ASSIGNED_TO_LARGE_DOUBLE_TEST));
|
||||
assertTrue(
|
||||
String.format(ASSERTION_MESSAGE_FOR_TYPE_CHECKS, "DOUBLE_ASSIGNED_TO_LARGE_FRACTIONAL_DOUBLE_TEST"),
|
||||
Double.class.isInstance(DoubleConstantsTestConstants.DOUBLE_ASSIGNED_TO_LARGE_FRACTIONAL_DOUBLE_TEST));
|
||||
//assertTrue(
|
||||
// String.format(ASSERTION_MESSAGE_FOR_TYPE_CHECKS, "DOUBLE_ASSIGNED_TO_SMALL_DOUBLE_TEST"),
|
||||
// Double.class.isInstance(DoubleConstantsTestConstants.DOUBLE_ASSIGNED_TO_SMALL_DOUBLE_TEST));
|
||||
assertTrue(
|
||||
String.format(
|
||||
ASSERTION_MESSAGE_FOR_TYPE_CHECKS, "DOUBLE_ASSIGNED_TO_NEGATIVE_BUT_LARGE_FRACTIONAL_DOUBLE_TEST"),
|
||||
Double.class.isInstance(
|
||||
DoubleConstantsTestConstants.DOUBLE_ASSIGNED_TO_NEGATIVE_BUT_LARGE_FRACTIONAL_DOUBLE_TEST));
|
||||
}
|
||||
}
|
3
vendor/git.apache.org/thrift.git/lib/java/test/org/apache/thrift/TestReuse.java
generated
vendored
3
vendor/git.apache.org/thrift.git/lib/java/test/org/apache/thrift/TestReuse.java
generated
vendored
|
@ -21,10 +21,7 @@ package org.apache.thrift;
|
|||
|
||||
import java.util.HashSet;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.thrift.protocol.TBinaryProtocol;
|
||||
import org.apache.thrift.protocol.TType;
|
||||
|
||||
import thrift.test.Reuse;
|
||||
|
||||
|
|
146
vendor/git.apache.org/thrift.git/lib/java/test/org/apache/thrift/TestUnsafeBinaries.java
generated
vendored
Normal file
146
vendor/git.apache.org/thrift.git/lib/java/test/org/apache/thrift/TestUnsafeBinaries.java
generated
vendored
Normal file
|
@ -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.thrift;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
|
||||
import thrift.test.SafeBytes;
|
||||
import thrift.test.UnsafeBytes;
|
||||
|
||||
// test generating types with un-copied byte[]/ByteBuffer input/output
|
||||
//
|
||||
public class TestUnsafeBinaries extends TestStruct {
|
||||
|
||||
private static byte[] input() {
|
||||
return new byte[]{1, 1};
|
||||
}
|
||||
|
||||
//
|
||||
// verify that the unsafe_binaries option modifies behavior
|
||||
//
|
||||
|
||||
// constructor doesn't copy
|
||||
public void testUnsafeConstructor() throws Exception {
|
||||
|
||||
byte[] input = input();
|
||||
UnsafeBytes struct = new UnsafeBytes(ByteBuffer.wrap(input));
|
||||
|
||||
input[0] = 2;
|
||||
|
||||
assertTrue(Arrays.equals(
|
||||
new byte[]{2, 1},
|
||||
struct.getBytes())
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
// getter doesn't copy
|
||||
// note: this behavior is the same with/without the flag, but if this default ever changes, the current behavior
|
||||
// should be retained when using this flag
|
||||
public void testUnsafeGetter(){
|
||||
UnsafeBytes struct = new UnsafeBytes(ByteBuffer.wrap(input()));
|
||||
|
||||
byte[] val = struct.getBytes();
|
||||
val[0] = 2;
|
||||
|
||||
assertTrue(Arrays.equals(
|
||||
new byte[]{2, 1},
|
||||
struct.getBytes())
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
// setter doesn't copy
|
||||
public void testUnsafeSetter(){
|
||||
UnsafeBytes struct = new UnsafeBytes();
|
||||
|
||||
byte[] val = input();
|
||||
struct.setBytes(val);
|
||||
|
||||
val[0] = 2;
|
||||
|
||||
assertTrue(Arrays.equals(
|
||||
new byte[]{2, 1},
|
||||
struct.getBytes())
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
// buffer doens't copy
|
||||
public void testUnsafeBufferFor(){
|
||||
UnsafeBytes struct = new UnsafeBytes(ByteBuffer.wrap(input()));
|
||||
|
||||
ByteBuffer val = struct.bufferForBytes();
|
||||
val.array()[0] = 2;
|
||||
|
||||
assertTrue(Arrays.equals(
|
||||
new byte[]{2, 1},
|
||||
struct.getBytes())
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
// verify that the default generator does not change behavior
|
||||
//
|
||||
|
||||
public void testSafeConstructor() {
|
||||
|
||||
byte[] input = input();
|
||||
SafeBytes struct = new SafeBytes(ByteBuffer.wrap(input));
|
||||
|
||||
input[0] = 2;
|
||||
|
||||
assertTrue(Arrays.equals(
|
||||
new byte[]{1, 1},
|
||||
struct.getBytes())
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public void testSafeSetter() {
|
||||
|
||||
byte[] input = input();
|
||||
SafeBytes struct = new SafeBytes(ByteBuffer.wrap(input));
|
||||
|
||||
input[0] = 2;
|
||||
|
||||
assertTrue(Arrays.equals(
|
||||
new byte[]{1, 1},
|
||||
struct.getBytes())
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public void testSafeBufferFor(){
|
||||
SafeBytes struct = new SafeBytes(ByteBuffer.wrap(input()));
|
||||
|
||||
ByteBuffer val = struct.bufferForBytes();
|
||||
val.array()[0] = 2;
|
||||
|
||||
assertTrue(Arrays.equals(
|
||||
new byte[]{1, 1},
|
||||
struct.getBytes())
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -18,24 +18,10 @@
|
|||
*/
|
||||
package org.apache.thrift.protocol;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.thrift.Fixtures;
|
||||
import org.apache.thrift.TBase;
|
||||
import org.apache.thrift.TDeserializer;
|
||||
import org.apache.thrift.TException;
|
||||
import org.apache.thrift.TSerializer;
|
||||
import org.apache.thrift.transport.TMemoryBuffer;
|
||||
|
||||
import thrift.test.CompactProtoTestStruct;
|
||||
import thrift.test.HolyMoley;
|
||||
import thrift.test.Nesting;
|
||||
import thrift.test.OneOfEach;
|
||||
import thrift.test.Srv;
|
||||
import thrift.test.GuessProtocolStruct;
|
||||
|
||||
public class TestTProtocolUtil extends TestCase {
|
||||
|
|
|
@ -84,7 +84,7 @@ public class TestTSimpleJSONProtocol extends TestCase {
|
|||
struct.unsetDouble_byte_map();
|
||||
struct.unsetString_byte_map();
|
||||
struct.write(proto);
|
||||
assertEquals("{\"a_byte\":127,\"a_i16\":32000,\"a_i32\":1000000000,\"a_i64\":1099511627775,\"a_double\":5.6789,\"a_string\":\"my string\",\"a_binary\":\"\\u0000\\u0001\\u0002\\u0003\\u0004\\u0005\\u0006\\u0007\\b\",\"true_field\":1,\"false_field\":0,\"empty_struct_field\":{},\"byte_list\":[-127,-1,0,1,127],\"i16_list\":[-1,0,1,32767],\"i32_list\":[-1,0,255,65535,16777215,2147483647],\"i64_list\":[-1,0,255,65535,16777215,4294967295,1099511627775,281474976710655,72057594037927935,9223372036854775807],\"double_list\":[0.1,0.2,0.3],\"string_list\":[\"first\",\"second\",\"third\"],\"boolean_list\":[1,1,1,0,0,0],\"struct_list\":[{},{}],\"i32_set\":[1,2,3],\"boolean_set\":[0,1],\"struct_set\":[{}],\"byte_byte_map\":{\"1\":2},\"boolean_byte_map\":{\"0\":0,\"1\":1},\"byte_i16_map\":{\"1\":1,\"2\":-1,\"3\":32767},\"byte_i32_map\":{\"1\":1,\"2\":-1,\"3\":2147483647},\"byte_i64_map\":{\"1\":1,\"2\":-1,\"3\":9223372036854775807},\"byte_double_map\":{\"1\":0.1,\"2\":-0.1,\"3\":1000000.0},\"byte_string_map\":{\"1\":\"\",\"2\":\"blah\",\"3\":\"loooooooooooooong string\"},\"byte_boolean_map\":{\"1\":1,\"2\":0},\"byte_map_map\":{\"0\":{},\"1\":{\"1\":1},\"2\":{\"1\":1,\"2\":2}},\"byte_set_map\":{\"0\":[],\"1\":[1],\"2\":[1,2]},\"byte_list_map\":{\"0\":[],\"1\":[1],\"2\":[1,2]}}", bufToString());
|
||||
assertEquals("{\"a_byte\":127,\"a_i16\":32000,\"a_i32\":1000000000,\"a_i64\":1099511627775,\"a_double\":5.6789,\"a_string\":\"my string\",\"a_binary\":\"\\u0000\\u0001\\u0002\\u0003\\u0004\\u0005\\u0006\\u0007\\b\",\"true_field\":1,\"false_field\":0,\"empty_struct_field\":{},\"byte_list\":[-127,-1,0,1,127],\"i16_list\":[-1,0,1,32767],\"i32_list\":[-1,0,255,65535,16777215,2147483647],\"i64_list\":[-1,0,255,65535,16777215,4294967295,1099511627775,281474976710655,72057594037927935,9223372036854775807],\"double_list\":[0.1,0.2,0.3],\"string_list\":[\"first\",\"second\",\"third\"],\"boolean_list\":[1,1,1,0,0,0],\"struct_list\":[{},{}],\"i32_set\":[1,2,3],\"boolean_set\":[0,1],\"struct_set\":[{}],\"byte_byte_map\":{\"1\":2},\"boolean_byte_map\":{\"0\":0,\"1\":1},\"byte_i16_map\":{\"1\":1,\"2\":-1,\"3\":32767},\"byte_i32_map\":{\"1\":1,\"2\":-1,\"3\":2147483647},\"byte_i64_map\":{\"1\":1,\"2\":-1,\"3\":9223372036854775807},\"byte_double_map\":{\"1\":0.1,\"2\":-0.1,\"3\":1000000.1},\"byte_string_map\":{\"1\":\"\",\"2\":\"blah\",\"3\":\"loooooooooooooong string\"},\"byte_boolean_map\":{\"1\":1,\"2\":0},\"byte_map_map\":{\"0\":{},\"1\":{\"1\":1},\"2\":{\"1\":1,\"2\":2}},\"byte_set_map\":{\"0\":[],\"1\":[1],\"2\":[1,2]},\"byte_list_map\":{\"0\":[],\"1\":[1],\"2\":[1,2]}}", bufToString());
|
||||
}
|
||||
|
||||
public void testThrowsOnCollectionKeys() throws TException {
|
||||
|
|
|
@ -54,13 +54,13 @@ import thrift.test.Xtruct2;
|
|||
public abstract class ServerTestBase extends TestCase {
|
||||
|
||||
public static class TestHandler implements ThriftTest.Iface {
|
||||
|
||||
|
||||
public TestHandler() {}
|
||||
|
||||
|
||||
public void testVoid() {
|
||||
System.out.print("testVoid()\n");
|
||||
}
|
||||
|
||||
|
||||
public String testString(String thing) {
|
||||
System.out.print("testString(\"" + thing + "\")\n");
|
||||
return thing;
|
||||
|
@ -70,22 +70,22 @@ public abstract class ServerTestBase extends TestCase {
|
|||
System.out.print("testBool(" + thing + ")\n");
|
||||
return thing;
|
||||
}
|
||||
|
||||
|
||||
public byte testByte(byte thing) {
|
||||
System.out.print("testByte(" + thing + ")\n");
|
||||
return thing;
|
||||
}
|
||||
|
||||
|
||||
public int testI32(int thing) {
|
||||
System.out.print("testI32(" + thing + ")\n");
|
||||
return thing;
|
||||
}
|
||||
|
||||
|
||||
public long testI64(long thing) {
|
||||
System.out.print("testI64(" + thing + ")\n");
|
||||
return thing;
|
||||
}
|
||||
|
||||
|
||||
public double testDouble(double thing) {
|
||||
System.out.print("testDouble(" + thing + ")\n");
|
||||
return thing;
|
||||
|
@ -110,7 +110,7 @@ public abstract class ServerTestBase extends TestCase {
|
|||
thing.i64_thing + "})\n");
|
||||
return thing;
|
||||
}
|
||||
|
||||
|
||||
public Xtruct2 testNest(Xtruct2 nest) {
|
||||
Xtruct thing = nest.struct_thing;
|
||||
System.out.print("testNest({" +
|
||||
|
@ -122,7 +122,7 @@ public abstract class ServerTestBase extends TestCase {
|
|||
nest.i32_thing + "})\n");
|
||||
return nest;
|
||||
}
|
||||
|
||||
|
||||
public Map<Integer,Integer> testMap(Map<Integer,Integer> thing) {
|
||||
System.out.print("testMap({");
|
||||
System.out.print(thing);
|
||||
|
@ -136,7 +136,7 @@ public abstract class ServerTestBase extends TestCase {
|
|||
System.out.print("})\n");
|
||||
return thing;
|
||||
}
|
||||
|
||||
|
||||
public Set<Integer> testSet(Set<Integer> thing) {
|
||||
System.out.print("testSet({");
|
||||
boolean first = true;
|
||||
|
@ -151,7 +151,7 @@ public abstract class ServerTestBase extends TestCase {
|
|||
System.out.print("})\n");
|
||||
return thing;
|
||||
}
|
||||
|
||||
|
||||
public List<Integer> testList(List<Integer> thing) {
|
||||
System.out.print("testList({");
|
||||
boolean first = true;
|
||||
|
@ -166,58 +166,58 @@ public abstract class ServerTestBase extends TestCase {
|
|||
System.out.print("})\n");
|
||||
return thing;
|
||||
}
|
||||
|
||||
|
||||
public Numberz testEnum(Numberz thing) {
|
||||
System.out.print("testEnum(" + thing + ")\n");
|
||||
return thing;
|
||||
}
|
||||
|
||||
|
||||
public long testTypedef(long thing) {
|
||||
System.out.print("testTypedef(" + thing + ")\n");
|
||||
return thing;
|
||||
}
|
||||
|
||||
|
||||
public Map<Integer,Map<Integer,Integer>> testMapMap(int hello) {
|
||||
System.out.print("testMapMap(" + hello + ")\n");
|
||||
Map<Integer,Map<Integer,Integer>> mapmap =
|
||||
new HashMap<Integer,Map<Integer,Integer>>();
|
||||
|
||||
|
||||
HashMap<Integer,Integer> pos = new HashMap<Integer,Integer>();
|
||||
HashMap<Integer,Integer> neg = new HashMap<Integer,Integer>();
|
||||
for (int i = 1; i < 5; i++) {
|
||||
pos.put(i, i);
|
||||
neg.put(-i, -i);
|
||||
}
|
||||
|
||||
|
||||
mapmap.put(4, pos);
|
||||
mapmap.put(-4, neg);
|
||||
|
||||
|
||||
return mapmap;
|
||||
}
|
||||
|
||||
|
||||
public Map<Long, Map<Numberz,Insanity>> testInsanity(Insanity argument) {
|
||||
System.out.print("testInsanity()\n");
|
||||
|
||||
|
||||
HashMap<Numberz,Insanity> first_map = new HashMap<Numberz, Insanity>();
|
||||
HashMap<Numberz,Insanity> second_map = new HashMap<Numberz, Insanity>();;
|
||||
|
||||
|
||||
first_map.put(Numberz.TWO, argument);
|
||||
first_map.put(Numberz.THREE, argument);
|
||||
|
||||
|
||||
Insanity looney = new Insanity();
|
||||
second_map.put(Numberz.SIX, looney);
|
||||
|
||||
|
||||
Map<Long,Map<Numberz,Insanity>> insane =
|
||||
new HashMap<Long, Map<Numberz,Insanity>>();
|
||||
insane.put((long)1, first_map);
|
||||
insane.put((long)2, second_map);
|
||||
|
||||
|
||||
return insane;
|
||||
}
|
||||
|
||||
|
||||
public Xtruct testMulti(byte arg0, int arg1, long arg2, Map<Short,String> arg3, Numberz arg4, long arg5) {
|
||||
System.out.print("testMulti()\n");
|
||||
|
||||
|
||||
Xtruct hello = new Xtruct();;
|
||||
hello.string_thing = "Hello2";
|
||||
hello.byte_thing = arg0;
|
||||
|
@ -225,7 +225,7 @@ public abstract class ServerTestBase extends TestCase {
|
|||
hello.i64_thing = arg2;
|
||||
return hello;
|
||||
}
|
||||
|
||||
|
||||
public void testException(String arg) throws Xception, TException {
|
||||
System.out.print("testException("+arg+")\n");
|
||||
if ("Xception".equals(arg)) {
|
||||
|
@ -234,14 +234,15 @@ public abstract class ServerTestBase extends TestCase {
|
|||
x.message = arg;
|
||||
throw x;
|
||||
} else if ("TException".equals(arg)) {
|
||||
throw new TException(arg);
|
||||
// Unspecified exception should yield a TApplicationException on client side
|
||||
throw new RuntimeException(arg);
|
||||
} else {
|
||||
Xtruct result = new Xtruct();
|
||||
result.string_thing = arg;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
public Xtruct testMultiException(String arg0, String arg1) throws Xception, Xception2 {
|
||||
System.out.print("testMultiException(" + arg0 + ", " + arg1 + ")\n");
|
||||
if (arg0.equals("Xception")) {
|
||||
|
@ -256,17 +257,17 @@ public abstract class ServerTestBase extends TestCase {
|
|||
x.struct_thing.string_thing = "This is an Xception2";
|
||||
throw x;
|
||||
}
|
||||
|
||||
|
||||
Xtruct result = new Xtruct();
|
||||
result.string_thing = arg1;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public void testOneway(int sleepFor) {
|
||||
System.out.println("testOneway(" + Integer.toString(sleepFor) +
|
||||
") => sleeping...");
|
||||
try {
|
||||
Thread.sleep(sleepFor * 1000);
|
||||
Thread.sleep(sleepFor * SLEEP_DELAY);
|
||||
System.out.println("Done sleeping!");
|
||||
} catch (InterruptedException ie) {
|
||||
throw new RuntimeException(ie);
|
||||
|
@ -281,6 +282,7 @@ public abstract class ServerTestBase extends TestCase {
|
|||
public static final String HOST = "localhost";
|
||||
public static final int PORT = Integer.valueOf(
|
||||
System.getProperty("test.port", "9090"));
|
||||
protected static final int SLEEP_DELAY = 1000;
|
||||
protected static final int SOCKET_TIMEOUT = 1500;
|
||||
private static final Xtruct XSTRUCT = new Xtruct("Zero", (byte) 1, -3, -5);
|
||||
private static final Xtruct2 XSTRUCT2 = new Xtruct2((byte)1, XSTRUCT, 5);
|
||||
|
@ -333,7 +335,7 @@ public abstract class ServerTestBase extends TestCase {
|
|||
// todo: add assertions
|
||||
private void testInsanity(ThriftTest.Client testClient) throws TException {
|
||||
Insanity insane;
|
||||
|
||||
|
||||
insane = new Insanity();
|
||||
insane.userMap = new HashMap<Numberz, Long>();
|
||||
insane.userMap.put(Numberz.FIVE, (long)5000);
|
||||
|
@ -351,7 +353,7 @@ public abstract class ServerTestBase extends TestCase {
|
|||
for (long key : whoa.keySet()) {
|
||||
Map<Numberz,Insanity> val = whoa.get(key);
|
||||
System.out.print(key + " => {");
|
||||
|
||||
|
||||
for (Numberz k2 : val.keySet()) {
|
||||
Insanity v2 = val.get(k2);
|
||||
System.out.print(k2 + " => {");
|
||||
|
@ -363,7 +365,7 @@ public abstract class ServerTestBase extends TestCase {
|
|||
}
|
||||
}
|
||||
System.out.print("}, ");
|
||||
|
||||
|
||||
List<Xtruct> xtructs = v2.xtructs;
|
||||
System.out.print("{");
|
||||
if (xtructs != null) {
|
||||
|
@ -372,7 +374,7 @@ public abstract class ServerTestBase extends TestCase {
|
|||
}
|
||||
}
|
||||
System.out.print("}");
|
||||
|
||||
|
||||
System.out.print("}, ");
|
||||
}
|
||||
System.out.print("}, ");
|
||||
|
@ -387,7 +389,7 @@ public abstract class ServerTestBase extends TestCase {
|
|||
public void testIt() throws Exception {
|
||||
|
||||
for (TProtocolFactory protoFactory : getProtocols()) {
|
||||
TProcessor processor = useAsyncProcessor() ? new ThriftTest.AsyncProcessor(new AsyncTestHandler()) : new ThriftTest.Processor(new TestHandler());
|
||||
TProcessor processor = useAsyncProcessor() ? new ThriftTest.AsyncProcessor<AsyncTestHandler>(new AsyncTestHandler()) : new ThriftTest.Processor<TestHandler>(new TestHandler());
|
||||
|
||||
startServer(processor, protoFactory);
|
||||
|
||||
|
@ -420,6 +422,7 @@ public abstract class ServerTestBase extends TestCase {
|
|||
testOneway(testClient);
|
||||
testI32(testClient);
|
||||
transport.close();
|
||||
socket.close();
|
||||
|
||||
stopServer();
|
||||
}
|
||||
|
@ -430,7 +433,7 @@ public abstract class ServerTestBase extends TestCase {
|
|||
}
|
||||
|
||||
public List<TProtocolFactory> getProtocols() {
|
||||
return PROTOCOLS;
|
||||
return PROTOCOLS;
|
||||
}
|
||||
|
||||
private void testList(ThriftTest.Client testClient) throws TException {
|
||||
|
@ -466,14 +469,14 @@ public abstract class ServerTestBase extends TestCase {
|
|||
testClient.testMapMap(1);
|
||||
Map<Integer,Map<Integer,Integer>> mapmap =
|
||||
new HashMap<Integer,Map<Integer,Integer>>();
|
||||
|
||||
|
||||
HashMap<Integer,Integer> pos = new HashMap<Integer,Integer>();
|
||||
HashMap<Integer,Integer> neg = new HashMap<Integer,Integer>();
|
||||
for (int i = 1; i < 5; i++) {
|
||||
pos.put(i, i);
|
||||
neg.put(-i, -i);
|
||||
}
|
||||
|
||||
|
||||
mapmap.put(4, pos);
|
||||
mapmap.put(-4, neg);
|
||||
assertEquals(mapmap, mm);
|
||||
|
@ -535,7 +538,7 @@ public abstract class ServerTestBase extends TestCase {
|
|||
public void testTransportFactory() throws Exception {
|
||||
for (TProtocolFactory protoFactory : getProtocols()) {
|
||||
TestHandler handler = new TestHandler();
|
||||
ThriftTest.Processor processor = new ThriftTest.Processor(handler);
|
||||
ThriftTest.Processor<TestHandler> processor = new ThriftTest.Processor<TestHandler>(handler);
|
||||
|
||||
final CallCountingTransportFactory factory = new CallCountingTransportFactory(new TFramedTransport.Factory());
|
||||
|
||||
|
@ -551,6 +554,7 @@ public abstract class ServerTestBase extends TestCase {
|
|||
ThriftTest.Client testClient = new ThriftTest.Client(protocol);
|
||||
assertEquals(0, testClient.testByte((byte) 0));
|
||||
assertEquals(2, factory.count);
|
||||
socket.close();
|
||||
stopServer();
|
||||
}
|
||||
}
|
||||
|
@ -679,13 +683,15 @@ public abstract class ServerTestBase extends TestCase {
|
|||
x.errorCode = 1001;
|
||||
x.message = arg;
|
||||
// throw and onError yield the same result.
|
||||
// resultHandler.onError(x);
|
||||
// return;
|
||||
throw x;
|
||||
} else if ("TException".equals(arg)) {
|
||||
// throw new TException(arg);
|
||||
resultHandler.onError(new TException(arg));
|
||||
// throw x;
|
||||
resultHandler.onError(x);
|
||||
return;
|
||||
} else if ("TException".equals(arg)) {
|
||||
// throw and onError yield the same result.
|
||||
// resultHandler.onError(new TException(arg));
|
||||
// return;
|
||||
// Unspecified exception should yield a TApplicationException on client side
|
||||
throw new RuntimeException(arg);
|
||||
}
|
||||
resultHandler.onComplete(null);
|
||||
}
|
||||
|
|
34
vendor/git.apache.org/thrift.git/lib/java/test/org/apache/thrift/test/TestClient.java
generated
vendored
34
vendor/git.apache.org/thrift.git/lib/java/test/org/apache/thrift/test/TestClient.java
generated
vendored
|
@ -33,6 +33,7 @@ import org.apache.thrift.TSerializer;
|
|||
import org.apache.thrift.protocol.TBinaryProtocol;
|
||||
import org.apache.thrift.protocol.TCompactProtocol;
|
||||
import org.apache.thrift.protocol.TJSONProtocol;
|
||||
import org.apache.thrift.protocol.TMultiplexedProtocol;
|
||||
import org.apache.thrift.protocol.TProtocol;
|
||||
import org.apache.thrift.protocol.TSimpleJSONProtocol;
|
||||
import org.apache.thrift.transport.TFastFramedTransport;
|
||||
|
@ -46,6 +47,7 @@ import org.apache.thrift.transport.TTransportException;
|
|||
// Generated code
|
||||
import thrift.test.Insanity;
|
||||
import thrift.test.Numberz;
|
||||
import thrift.test.SecondService;
|
||||
import thrift.test.ThriftTest;
|
||||
import thrift.test.Xception;
|
||||
import thrift.test.Xception2;
|
||||
|
@ -64,6 +66,7 @@ public class TestClient {
|
|||
private static int ERR_STRUCTS = 2;
|
||||
private static int ERR_CONTAINERS = 4;
|
||||
private static int ERR_EXCEPTIONS = 8;
|
||||
private static int ERR_PROTOCOLS = 16;
|
||||
private static int ERR_UNKNOWN = 64;
|
||||
|
||||
public static void main(String [] args) {
|
||||
|
@ -102,7 +105,7 @@ public class TestClient {
|
|||
System.out.println(" --host=arg (=" + host + ")\tHost to connect");
|
||||
System.out.println(" --port=arg (=" + port + ")\tPort number to connect");
|
||||
System.out.println(" --transport=arg (=" + transport_type + ")\n\t\t\t\tTransport: buffered, framed, fastframed, http");
|
||||
System.out.println(" --protocol=arg (=" + protocol_type + ")\tProtocol: binary, json, compact");
|
||||
System.out.println(" --protocol=arg (=" + protocol_type + ")\tProtocol: binary, compact, json, multi, multic, multij");
|
||||
System.out.println(" --ssl\t\t\tEncrypted Transport using SSL");
|
||||
System.out.println(" --testloops[--n]=arg (=" + numTests + ")\tNumber of Tests");
|
||||
System.exit(0);
|
||||
|
@ -117,6 +120,9 @@ public class TestClient {
|
|||
if (protocol_type.equals("binary")) {
|
||||
} else if (protocol_type.equals("compact")) {
|
||||
} else if (protocol_type.equals("json")) {
|
||||
} else if (protocol_type.equals("multi")) {
|
||||
} else if (protocol_type.equals("multic")) {
|
||||
} else if (protocol_type.equals("multij")) {
|
||||
} else {
|
||||
throw new Exception("Unknown protocol type! " + protocol_type);
|
||||
}
|
||||
|
@ -163,16 +169,21 @@ public class TestClient {
|
|||
}
|
||||
|
||||
TProtocol tProtocol = null;
|
||||
if (protocol_type.equals("json")) {
|
||||
TProtocol tProtocol2 = null;
|
||||
if (protocol_type.equals("json") || protocol_type.equals("multij")) {
|
||||
tProtocol = new TJSONProtocol(transport);
|
||||
} else if (protocol_type.equals("compact")) {
|
||||
} else if (protocol_type.equals("compact") || protocol_type.equals("multic")) {
|
||||
tProtocol = new TCompactProtocol(transport);
|
||||
} else {
|
||||
tProtocol = new TBinaryProtocol(transport);
|
||||
}
|
||||
|
||||
ThriftTest.Client testClient =
|
||||
new ThriftTest.Client(tProtocol);
|
||||
if (protocol_type.startsWith("multi")) {
|
||||
tProtocol2 = new TMultiplexedProtocol(tProtocol, "SecondService");
|
||||
tProtocol = new TMultiplexedProtocol(tProtocol, "ThriftTest");
|
||||
}
|
||||
|
||||
ThriftTest.Client testClient = new ThriftTest.Client(tProtocol);
|
||||
Insanity insane = new Insanity();
|
||||
|
||||
long timeMin = 0;
|
||||
|
@ -222,6 +233,19 @@ public class TestClient {
|
|||
System.out.println("*** FAILURE ***\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiplexed test
|
||||
*/
|
||||
if (protocol_type.startsWith("multi")) {
|
||||
SecondService.Client secondClient = new SecondService.Client(tProtocol2);
|
||||
System.out.print("secondtestString(\"Test2\")");
|
||||
s = secondClient.secondtestString("Test2");
|
||||
System.out.print(" = \"" + s + "\"\n");
|
||||
if (!s.equals("testString(\"Test2\")")) {
|
||||
returnCode |= ERR_PROTOCOLS;
|
||||
System.out.println("*** FAILURE ***\n");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* BYTE TEST
|
||||
*/
|
||||
|
|
72
vendor/git.apache.org/thrift.git/lib/java/test/org/apache/thrift/test/TestServer.java
generated
vendored
72
vendor/git.apache.org/thrift.git/lib/java/test/org/apache/thrift/test/TestServer.java
generated
vendored
|
@ -30,6 +30,7 @@ import org.apache.thrift.protocol.TCompactProtocol;
|
|||
import org.apache.thrift.protocol.TJSONProtocol;
|
||||
import org.apache.thrift.protocol.TProtocol;
|
||||
import org.apache.thrift.protocol.TProtocolFactory;
|
||||
import org.apache.thrift.protocol.TMultiplexedProtocol;
|
||||
import org.apache.thrift.server.ServerContext;
|
||||
import org.apache.thrift.server.TServer;
|
||||
import org.apache.thrift.server.TServer.Args;
|
||||
|
@ -46,10 +47,11 @@ import org.apache.thrift.transport.TSSLTransportFactory;
|
|||
import org.apache.thrift.transport.TTransport;
|
||||
import org.apache.thrift.transport.TTransportFactory;
|
||||
import org.apache.thrift.transport.TNonblockingServerSocket;
|
||||
|
||||
import org.apache.thrift.TMultiplexedProcessor;
|
||||
|
||||
import thrift.test.Insanity;
|
||||
import thrift.test.Numberz;
|
||||
import thrift.test.SecondService;
|
||||
import thrift.test.ThriftTest;
|
||||
import thrift.test.Xception;
|
||||
import thrift.test.Xception2;
|
||||
|
@ -58,6 +60,24 @@ import thrift.test.Xtruct2;
|
|||
|
||||
public class TestServer {
|
||||
|
||||
// Multiplexed Protocol Support Details:
|
||||
//
|
||||
// For multiplexed testing we always use binary protocol underneath.
|
||||
//
|
||||
// "ThriftTest" named service implements "ThriftTest" from ThriftTest.thrift
|
||||
// "SecondService" named service implements "SecondService" from ThriftTest.thrift
|
||||
// In addition, to support older non-multiplexed clients using the same concrete protocol
|
||||
// the multiplexed processor is taught to use "ThriftTest" if the incoming request has no
|
||||
// multiplexed call name decoration.
|
||||
|
||||
static class SecondHandler implements thrift.test.SecondService.Iface {
|
||||
|
||||
@Override
|
||||
public java.lang.String secondtestString(java.lang.String thing) throws org.apache.thrift.TException
|
||||
{ return "testString(\"" + thing + "\")"; }
|
||||
|
||||
}
|
||||
|
||||
static class TestServerContext implements ServerContext {
|
||||
|
||||
int connectionId;
|
||||
|
@ -139,7 +159,7 @@ public class TestServer {
|
|||
System.out.println(" --help\t\t\tProduce help message");
|
||||
System.out.println(" --port=arg (=" + port + ")\tPort number to connect");
|
||||
System.out.println(" --transport=arg (=" + transport_type + ")\n\t\t\t\tTransport: buffered, framed, fastframed");
|
||||
System.out.println(" --protocol=arg (=" + protocol_type + ")\tProtocol: binary, json, compact");
|
||||
System.out.println(" --protocol=arg (=" + protocol_type + ")\tProtocol: binary, compact, json, multi, multic, multij");
|
||||
System.out.println(" --ssl\t\t\tEncrypted Transport using SSL");
|
||||
System.out.println(" --server-type=arg (=" + server_type +")\n\t\t\t\tType of server: simple, thread-pool, nonblocking, threaded-selector");
|
||||
System.out.println(" --string-limit=arg (=" + string_limit + ")\tString read length limit");
|
||||
|
@ -167,8 +187,11 @@ public class TestServer {
|
|||
throw new Exception("Unknown server type! " + server_type);
|
||||
}
|
||||
if (protocol_type.equals("binary")) {
|
||||
} else if (protocol_type.equals("json")) {
|
||||
} else if (protocol_type.equals("compact")) {
|
||||
} else if (protocol_type.equals("json")) {
|
||||
} else if (protocol_type.equals("multi")) {
|
||||
} else if (protocol_type.equals("multic")) {
|
||||
} else if (protocol_type.equals("multij")) {
|
||||
} else {
|
||||
throw new Exception("Unknown protocol type! " + protocol_type);
|
||||
}
|
||||
|
@ -183,19 +206,20 @@ public class TestServer {
|
|||
System.exit(1);
|
||||
}
|
||||
|
||||
// Processor
|
||||
TestHandler testHandler =
|
||||
new TestHandler();
|
||||
ThriftTest.Processor testProcessor =
|
||||
new ThriftTest.Processor(testHandler);
|
||||
// Processors
|
||||
TestHandler testHandler = new TestHandler();
|
||||
ThriftTest.Processor testProcessor = new ThriftTest.Processor(testHandler);
|
||||
|
||||
SecondHandler secondHandler = new SecondHandler();
|
||||
SecondService.Processor secondProcessor = new SecondService.Processor(secondHandler);
|
||||
|
||||
// Protocol factory
|
||||
TProtocolFactory tProtocolFactory = null;
|
||||
if (protocol_type.equals("json")) {
|
||||
if (protocol_type.equals("json") || protocol_type.equals("multij")) {
|
||||
tProtocolFactory = new TJSONProtocol.Factory();
|
||||
} else if (protocol_type.equals("compact")) {
|
||||
} else if (protocol_type.equals("compact") || protocol_type.equals("multic")) {
|
||||
tProtocolFactory = new TCompactProtocol.Factory(string_limit, container_limit);
|
||||
} else {
|
||||
} else { // also covers multi
|
||||
tProtocolFactory = new TBinaryProtocol.Factory(string_limit, container_limit);
|
||||
}
|
||||
|
||||
|
@ -211,6 +235,11 @@ public class TestServer {
|
|||
|
||||
TServer serverEngine = null;
|
||||
|
||||
// If we are multiplexing services in one server...
|
||||
TMultiplexedProcessor multiplexedProcessor = new TMultiplexedProcessor();
|
||||
multiplexedProcessor.registerDefault (testProcessor);
|
||||
multiplexedProcessor.registerProcessor("ThriftTest", testProcessor);
|
||||
multiplexedProcessor.registerProcessor("SecondService", secondProcessor);
|
||||
|
||||
if (server_type.equals("nonblocking") ||
|
||||
server_type.equals("threaded-selector")) {
|
||||
|
@ -218,23 +247,21 @@ public class TestServer {
|
|||
TNonblockingServerSocket tNonblockingServerSocket =
|
||||
new TNonblockingServerSocket(new TNonblockingServerSocket.NonblockingAbstractServerSocketArgs().port(port));
|
||||
|
||||
if (server_type.equals("nonblocking")) {
|
||||
if (server_type.contains("nonblocking")) {
|
||||
// Nonblocking Server
|
||||
TNonblockingServer.Args tNonblockingServerArgs
|
||||
= new TNonblockingServer.Args(tNonblockingServerSocket);
|
||||
tNonblockingServerArgs.processor(testProcessor);
|
||||
tNonblockingServerArgs.processor(protocol_type.startsWith("multi") ? multiplexedProcessor : testProcessor);
|
||||
tNonblockingServerArgs.protocolFactory(tProtocolFactory);
|
||||
tNonblockingServerArgs.transportFactory(tTransportFactory);
|
||||
|
||||
serverEngine = new TNonblockingServer(tNonblockingServerArgs);
|
||||
} else { // server_type.equals("threaded-selector")
|
||||
// ThreadedSelector Server
|
||||
TThreadedSelectorServer.Args tThreadedSelectorServerArgs
|
||||
= new TThreadedSelectorServer.Args(tNonblockingServerSocket);
|
||||
tThreadedSelectorServerArgs.processor(testProcessor);
|
||||
tThreadedSelectorServerArgs.processor(protocol_type.startsWith("multi") ? multiplexedProcessor : testProcessor);
|
||||
tThreadedSelectorServerArgs.protocolFactory(tProtocolFactory);
|
||||
tThreadedSelectorServerArgs.transportFactory(tTransportFactory);
|
||||
|
||||
serverEngine = new TThreadedSelectorServer(tThreadedSelectorServerArgs);
|
||||
}
|
||||
} else {
|
||||
|
@ -251,29 +278,28 @@ public class TestServer {
|
|||
if (server_type.equals("simple")) {
|
||||
// Simple Server
|
||||
TServer.Args tServerArgs = new TServer.Args(tServerSocket);
|
||||
tServerArgs.processor(testProcessor);
|
||||
tServerArgs.processor(protocol_type.startsWith("multi") ? multiplexedProcessor : testProcessor);
|
||||
tServerArgs.protocolFactory(tProtocolFactory);
|
||||
tServerArgs.transportFactory(tTransportFactory);
|
||||
|
||||
serverEngine = new TSimpleServer(tServerArgs);
|
||||
} else { // server_type.equals("threadpool")
|
||||
// ThreadPool Server
|
||||
TThreadPoolServer.Args tThreadPoolServerArgs
|
||||
= new TThreadPoolServer.Args(tServerSocket);
|
||||
tThreadPoolServerArgs.processor(testProcessor);
|
||||
tThreadPoolServerArgs.processor(protocol_type.startsWith("multi") ? multiplexedProcessor : testProcessor);
|
||||
tThreadPoolServerArgs.protocolFactory(tProtocolFactory);
|
||||
tThreadPoolServerArgs.transportFactory(tTransportFactory);
|
||||
|
||||
serverEngine = new TThreadPoolServer(tThreadPoolServerArgs);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Set server event handler
|
||||
// Set server event handler
|
||||
serverEngine.setServerEventHandler(new TestServerEventHandler());
|
||||
|
||||
// Run it
|
||||
System.out.println("Starting the server on port " + port + "...");
|
||||
System.out.println("Starting the " + (ssl ? "ssl server" : "server") +
|
||||
" [" + protocol_type + "/" + transport_type + "/" + server_type + "] on " +
|
||||
((domain_socket == "") ? ("port " + port) : ("unix socket " + domain_socket)));
|
||||
serverEngine.serve();
|
||||
|
||||
} catch (Exception x) {
|
||||
|
|
|
@ -19,13 +19,15 @@
|
|||
package org.apache.thrift.transport;
|
||||
|
||||
public class TestTFastFramedTransport extends TestTFramedTransport {
|
||||
protected final static int INITIAL_CAPACITY = 50;
|
||||
|
||||
@Override
|
||||
protected TTransport getTransport(TTransport underlying) {
|
||||
return new TFastFramedTransport(underlying, 50, 10 * 1024 * 1024);
|
||||
return new TFastFramedTransport(underlying, INITIAL_CAPACITY, 10 * 1024 * 1024);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TTransport getTransport(TTransport underlying, int maxLength) {
|
||||
return new TFastFramedTransport(underlying, 50, maxLength);
|
||||
return new TFastFramedTransport(underlying, INITIAL_CAPACITY, maxLength);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -183,4 +183,32 @@ public class TestTFramedTransport extends TestCase {
|
|||
assertEquals(65, trans.getBytesRemainingInBuffer());
|
||||
assertEquals(10, trans.getBufferPosition());
|
||||
}
|
||||
|
||||
public void testClear() throws IOException, TTransportException {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
DataOutputStream dos = new DataOutputStream(baos);
|
||||
dos.writeInt(220);
|
||||
dos.write(byteSequence(0, 219));
|
||||
|
||||
TMemoryBuffer membuf = new TMemoryBuffer(0);
|
||||
membuf.write(baos.toByteArray());
|
||||
|
||||
ReadCountingTransport countTrans = new ReadCountingTransport(membuf);
|
||||
TTransport trans = getTransport(countTrans);
|
||||
|
||||
byte[] readBuf = new byte[220];
|
||||
trans.read(readBuf, 0, 220);
|
||||
assertTrue(Arrays.equals(readBuf, byteSequence(0,219)));
|
||||
|
||||
assertTrue(trans instanceof TFramedTransport || trans instanceof TFastFramedTransport);
|
||||
if (trans instanceof TFramedTransport) {
|
||||
assertTrue(trans.getBuffer() != null && trans.getBuffer().length > 0);
|
||||
((TFramedTransport) trans).clear();
|
||||
assertTrue(trans.getBuffer() == null);
|
||||
} else if (trans instanceof TFastFramedTransport) {
|
||||
assertTrue(trans.getBuffer().length > TestTFastFramedTransport.INITIAL_CAPACITY);
|
||||
((TFastFramedTransport) trans).clear();
|
||||
assertTrue(trans.getBuffer().length == TestTFastFramedTransport.INITIAL_CAPACITY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,6 +45,10 @@ public class TestTSSLTransportFactory extends ServerTestBase {
|
|||
throws Exception {
|
||||
return TSSLTransportFactory.getClientSocket(HOST, PORT);
|
||||
}
|
||||
|
||||
protected TServerSocket getServerTransport() throws Exception {
|
||||
return TSSLTransportFactory.getServerSocket(PORT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startServer(final TProcessor processor, final TProtocolFactory protoFactory, final TTransportFactory factory)
|
||||
|
@ -52,11 +56,11 @@ public class TestTSSLTransportFactory extends ServerTestBase {
|
|||
serverThread = new Thread() {
|
||||
public void run() {
|
||||
try {
|
||||
TServerTransport serverTransport = TSSLTransportFactory.getServerSocket(PORT);
|
||||
TServerTransport serverTransport = getServerTransport();
|
||||
final Args args = new Args(serverTransport).processor(processor);
|
||||
server = new TSimpleServer(args);
|
||||
server.serve();
|
||||
} catch (TTransportException e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
assert false;
|
||||
}
|
||||
|
@ -64,7 +68,7 @@ public class TestTSSLTransportFactory extends ServerTestBase {
|
|||
};
|
||||
|
||||
serverThread.start();
|
||||
Thread.sleep(1000);
|
||||
Thread.sleep(SLEEP_DELAY);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
62
vendor/git.apache.org/thrift.git/lib/java/test/org/apache/thrift/transport/TestTSSLTransportFactoryStreamedStore.java
generated
vendored
Normal file
62
vendor/git.apache.org/thrift.git/lib/java/test/org/apache/thrift/transport/TestTSSLTransportFactoryStreamedStore.java
generated
vendored
Normal file
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* 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.thrift.transport;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.net.InetAddress;
|
||||
|
||||
public class TestTSSLTransportFactoryStreamedStore extends TestTSSLTransportFactory {
|
||||
private static String keyStoreLocation = System.getProperty("javax.net.ssl.keyStore");
|
||||
private static String trustStoreLocation = System.getProperty("javax.net.ssl.trustStore");
|
||||
|
||||
public TestTSSLTransportFactoryStreamedStore() {
|
||||
super();
|
||||
|
||||
/**
|
||||
* Override system properties to be able to test passing
|
||||
* the trustStore and keyStore as input stream
|
||||
*/
|
||||
System.setProperty("javax.net.ssl.trustStore", "");
|
||||
System.setProperty("javax.net.ssl.keyStore", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TTransport getClientTransport(TTransport underlyingTransport)
|
||||
throws Exception {
|
||||
TSSLTransportFactory.TSSLTransportParameters params = new
|
||||
TSSLTransportFactory.TSSLTransportParameters();
|
||||
|
||||
params.setTrustStore(new FileInputStream(trustStoreLocation),
|
||||
System.getProperty("javax.net.ssl.trustStorePassword"));
|
||||
|
||||
return TSSLTransportFactory.getClientSocket(HOST, PORT, 0/*timeout*/, params);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TServerSocket getServerTransport() throws Exception {
|
||||
TSSLTransportFactory.TSSLTransportParameters params = new
|
||||
TSSLTransportFactory.TSSLTransportParameters();
|
||||
|
||||
params.setKeyStore(new FileInputStream(keyStoreLocation),
|
||||
System.getProperty("javax.net.ssl.keyStorePassword"));
|
||||
|
||||
return TSSLTransportFactory.getServerSocket(PORT, 0/*timeout*/, InetAddress.getByName(HOST), params);
|
||||
}
|
||||
}
|
|
@ -27,21 +27,21 @@ public class TestTSimpleFileTransport extends TestCase {
|
|||
public void testFresh() throws Exception {
|
||||
//Test write side
|
||||
Path tempFilePathName = Files.createTempFile("TSimpleFileTransportTest", null);
|
||||
Files.delete(tempFilePathName);
|
||||
Files.delete(tempFilePathName);
|
||||
byte[] input_buf = new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
|
||||
TSimpleFileTransport trans_write = new TSimpleFileTransport(tempFilePathName.toString(),false, true, false);
|
||||
assert (!trans_write.isOpen());
|
||||
trans_write.open();
|
||||
assert(trans_write.isOpen());
|
||||
trans_write.write(input_buf);
|
||||
trans_write.write(input_buf,2,2);
|
||||
trans_write.write(input_buf,2,2);
|
||||
trans_write.flush();
|
||||
trans_write.close();
|
||||
|
||||
|
||||
//Test read side
|
||||
TSimpleFileTransport trans = new TSimpleFileTransport(tempFilePathName.toString(),true, false);
|
||||
assert(trans_write.isOpen());
|
||||
|
||||
assert(trans.isOpen());
|
||||
|
||||
//Simple file trans provides no buffer access
|
||||
assert(0 == trans.getBufferPosition());
|
||||
assert(null == trans.getBuffer());
|
||||
|
@ -56,19 +56,19 @@ public class TestTSimpleFileTransport extends TestCase {
|
|||
trans.readAll(buf1, 0, BUFSIZ);
|
||||
assert(BUFSIZ == trans.getFilePointer());
|
||||
assert(Arrays.equals(new byte[]{1, 2, 3, 4}, buf1));
|
||||
|
||||
|
||||
int bytesRead = trans.read(buf1, 0, BUFSIZ);
|
||||
assert(bytesRead > 0);
|
||||
for (int i = 0; i < bytesRead; ++i) {
|
||||
assert(buf1[i] == i+5);
|
||||
assert(buf1[i] == i+5);
|
||||
}
|
||||
|
||||
|
||||
trans.seek(0);
|
||||
assert(0 == trans.getFilePointer());
|
||||
trans.readAll(buf1, 0, BUFSIZ);
|
||||
assert(Arrays.equals(new byte[]{1, 2, 3, 4}, buf1));
|
||||
assert(BUFSIZ == trans.getFilePointer());
|
||||
trans.close();
|
||||
Files.delete(tempFilePathName);
|
||||
Files.delete(tempFilePathName);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue