Skip to content

Commit

Permalink
Add a test for exceptions with corba any variables
Browse files Browse the repository at this point in the history
Prior to the changes in "Issue unmarshalling user exception with Any"
during the test: test_relative_roundtrip_fwdcall_at_rec_exc_with_any_OK
we would get a marshal exception indicating the wrong id.  The code
expects to see the id type name of the exception, but the input stream
was reset to the location of the any variable due to the stream getting
marked while reading the valuetype.
  • Loading branch information
Daniel Kempenich committed Mar 24, 2020
1 parent b781d11 commit 8c3ef69
Show file tree
Hide file tree
Showing 13 changed files with 141 additions and 0 deletions.
4 changes: 4 additions & 0 deletions test/regression/src/test/idl/ExceptionServer.idl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module org
string message;
};


interface ExceptionServer
{
void throwRuntimeException(in string message);
Expand All @@ -23,6 +24,9 @@ module org

void throwUserExceptionWithMessage2(in string reason, in string message)
raises (MyUserException);

void throwAnyException(in string reason, in any anything)
raises (AnyException);
};
};
};
Expand Down
6 changes: 6 additions & 0 deletions test/regression/src/test/idl/Tests.idl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ module org
string field2;
};

// example Exception with any type
exception AnyException
{
any anything;
};

// example unbounded Sequence
typedef sequence< long > UnboundedData;

Expand Down
1 change: 1 addition & 0 deletions test/regression/src/test/idl/TimingServer.idl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module org
{
long operation (in long id, in long delay);
char ex_op (in char ch, in long delay) raises (EmptyException);
void any_ex_op (in string reason, in any anything, in long delay) raises (AnyException);

long long server_time (in long delay);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.jacorb.test.bugs.bug940;

import org.jacorb.test.AnyException;
import org.jacorb.test.EmptyException;
import org.jacorb.test.TimingServerPOA;
import org.omg.CORBA.Any;

public class TimingServerImpl extends TimingServerPOA
{
Expand Down Expand Up @@ -30,6 +32,13 @@ else if (ch == '$')
}
}

@Override
public void any_ex_op(String reason, Any anything, int delay) throws AnyException
{
sleep(delay);
throw new AnyException(reason, anything);
}

@Override
public long server_time(int delay)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.jacorb.test.bugs.bugjac493;

import org.jacorb.test.AnyException;
import org.jacorb.test.EmptyException;
import org.jacorb.test.TimingServerPOA;
import org.omg.CORBA.Any;

public class TimingServerImpl extends TimingServerPOA
{
Expand All @@ -28,6 +30,12 @@ else if (ch == '$')
}
}

public void any_ex_op(String reason, Any anything, int delay) throws AnyException
{
sleep(delay);
throw new AnyException(reason, anything);
}

public long server_time(int delay)
{
long time = System.currentTimeMillis();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,21 @@ public void ex_op_excep(ExceptionHolder excep_holder)
wrong_exception ("ex_op_excep", excep_holder);
}

public void any_ex_op_excep(ExceptionHolder excep_holder)
{
wrong_exception ("any_ex_op_excep", excep_holder);
}

public void ex_op(char ami_return_val)
{
wrong_reply ("ex_op");
}

public void any_ex_op()
{
wrong_reply ("any_ex_op");
}

public void operation_excep(ExceptionHolder excep_holder)
{
wrong_exception ("operation_excep", excep_holder);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.jacorb.test.bugs.bugrtj634;

import org.jacorb.test.AnyException;
import org.jacorb.test.ComplexTimingServerPOA;
import org.jacorb.test.EmptyException;
import org.omg.CORBA.Any;
import org.omg.CORBA.NO_IMPLEMENT;
import org.omg.CORBA.Object;

Expand Down Expand Up @@ -30,6 +32,11 @@ public char ex_op(char ch, int delay) throws EmptyException
throw new NO_IMPLEMENT();
}

public void any_ex_op(String reason, Any anything, int delay) throws AnyException
{
throw new NO_IMPLEMENT();
}

public long server_time(int delay)
{
throw new NO_IMPLEMENT();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package org.jacorb.test.orb;

import org.jacorb.test.AnyException;
import org.jacorb.test.ExceptionServerPOA;
import org.jacorb.test.MyUserException;
import org.jacorb.test.NonEmptyException;
import org.omg.CORBA.Any;

public class ExceptionServerImpl extends ExceptionServerPOA
{
Expand All @@ -25,4 +27,10 @@ public void throwUserExceptionWithMessage2(String reason, String message) throws
{
throw new MyUserException(reason, message);
}

public void throwAnyException(String reason, Any anything) throws AnyException
{
throw new AnyException(reason, anything);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import org.jacorb.test.AnyException;
import org.jacorb.test.ExceptionServer;
import org.jacorb.test.ExceptionServerHelper;
import org.jacorb.test.MyUserException;
Expand All @@ -13,6 +14,7 @@
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.omg.CORBA.Any;

/**
* This class gathers all sorts of exception-related tests.
Expand Down Expand Up @@ -109,4 +111,23 @@ public void testUserExceptionWithData()
assertEquals("sample message", e.message);
}
}

@Test
public void testExceptionWithAny()
{
try
{
Any any = setup.getClientOrb().create_any();
any.insert_long(73);
server.throwAnyException("sample reason", any);
fail("Expected an exception to be thrown");
}
catch(AnyException e)
{
// expected
assertEquals("sample reason", e.getMessage());
assertEquals(73, e.anything.extract_long());
}
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.jacorb.test.orb.policies;

import org.jacorb.test.AnyException;
import org.jacorb.test.ComplexTimingServerPOA;
import org.jacorb.test.EmptyException;
import org.omg.CORBA.Any;

public class ComplexTimingServerImpl extends ComplexTimingServerPOA
{
Expand Down Expand Up @@ -43,6 +45,12 @@ else if (ch == '$')
}
}

public void any_ex_op(String reason, Any anything, int delay) throws AnyException
{
sleep(delay);
throw new AnyException(reason, anything);
}

public long server_time(int delay)
{
long time = System.currentTimeMillis();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.jacorb.test.AMI_ComplexTimingServerHandler;
import org.jacorb.test.AMI_ComplexTimingServerHandlerOperations;
import org.jacorb.test.AMI_ComplexTimingServerHandlerPOATie;
import org.jacorb.test.AnyException;
import org.jacorb.test.ComplexTimingServer;
import org.jacorb.test.ComplexTimingServerHelper;
import org.jacorb.test.EmptyException;
Expand All @@ -18,6 +19,7 @@
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.omg.CORBA.Any;
import org.omg.CORBA.Policy;
import org.omg.CORBA.PolicyError;
import org.omg.CORBA.SetOverrideType;
Expand Down Expand Up @@ -87,11 +89,21 @@ public void ex_op_excep (ExceptionHolder excep_holder)
wrong_exception ("ex_op_excep", excep_holder);
}

public void any_ex_op_excep(ExceptionHolder excep_holder)
{
wrong_exception ("any_ex_op_excep", excep_holder);
}

public void ex_op (char ami_return_val)
{
wrong_reply ("ex_op");
}

public void any_ex_op()
{
wrong_reply ("any_ex_op");
}

public void operation_excep (ExceptionHolder excep_holder)
{
wrong_exception ("operation_excep", excep_holder);
Expand Down Expand Up @@ -643,6 +655,7 @@ public void test_relative_roundtrip_fwdcall_at_rec_exc_OK()
try
{
server.ex_op ('e', 50);
fail("EmptyException is expected");
}
catch (org.omg.CORBA.TIMEOUT t)
{
Expand All @@ -654,6 +667,34 @@ public void test_relative_roundtrip_fwdcall_at_rec_exc_OK()
}
}

@Test
public void test_relative_roundtrip_fwdcall_at_rec_exc_with_any_OK()
{
server = clearPolicies (server);
server = setRelativeRoundtripTimeout (server, 400);

ClientInterceptor.forwardCallMade = false;

TestConfig.setConfig (TestConfig.CALL_AT_REC_EX,
fwdServer);

try
{
Any any = setup.getClientOrb().create_any();
any.insert_long(73);
server.any_ex_op ("message", any, 50);
fail("AnyException is expected");
}
catch (org.omg.CORBA.TIMEOUT t)
{
fail ("FAIL TIMEOUT not expected");
}
catch (AnyException ee)
{
// OK
}
}

@Test
public void test_relative_roundtrip_fwdcall_at_rec_exc_exp()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.jacorb.test.orb.policies;

import org.jacorb.test.AnyException;
import org.jacorb.test.EmptyException;
import org.jacorb.test.TimingServerPOA;
import org.omg.CORBA.Any;

public class TimingServerImpl extends TimingServerPOA
{
Expand All @@ -28,6 +30,12 @@ else if (ch == '$')
}
}

public void any_ex_op(String reason, Any anything, int delay) throws AnyException
{
sleep(delay);
throw new AnyException(reason, anything);
}

public long server_time(int delay)
{
long time = System.currentTimeMillis();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,21 @@ public void ex_op_excep(ExceptionHolder excep_holder)
wrong_exception ("ex_op_excep", excep_holder);
}

public void any_ex_op_excep(ExceptionHolder excep_holder)
{
wrong_exception ("any_ex_op_excep", excep_holder);
}

public void ex_op(char ami_return_val)
{
wrong_reply ("ex_op");
}

public void any_ex_op()
{
wrong_reply ("any_ex_op");
}

public void operation_excep(ExceptionHolder excep_holder)
{
wrong_exception ("operation_excep", excep_holder);
Expand Down

0 comments on commit 8c3ef69

Please sign in to comment.