Skip to content

Commit

Permalink
Merge pull request #1161 from Marketcetera/unit_tests
Browse files Browse the repository at this point in the history
Unit test fixes
  • Loading branch information
colinduplantis committed Apr 24, 2023
2 parents 9784fe7 + 37c6b6e commit b61213b
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 26 deletions.
5 changes: 5 additions & 0 deletions core/src/main/java/org/marketcetera/module/ModuleManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import javax.annotation.concurrent.GuardedBy;
import javax.management.DynamicMBean;
import javax.management.InstanceAlreadyExistsException;
import javax.management.JMException;
import javax.management.JMX;
import javax.management.MBeanAttributeInfo;
Expand Down Expand Up @@ -1794,6 +1795,10 @@ private ObjectName registerMXBean(Object inMXBean, ObjectName inObjectName)
try {
//Register the factory with the mbean server
getMBeanServer().registerMBean(proxy, inObjectName);
} catch (InstanceAlreadyExistsException e) {
Messages.BEAN_REGISTRATION_ERROR.warn(this,
e,
inObjectName);
} catch (JMException e) {
Messages.BEAN_REGISTRATION_ERROR.warn(this,
e,
Expand Down
8 changes: 4 additions & 4 deletions dare/src/test/java/org/marketcetera/ors/OrderStatusTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void testReplaceUpdatesOrderRecord(Instrument inInstrument)
order1.setPrice(order1Price);
order1.setQuantity(order1Qty);
order1.setSide(Side.Buy);
client.sendOrder(order1);
tradeClient.sendOrder(order1);
quickfix.Message receivedOrder1 = waitForAndVerifySenderMessage(sender1,
quickfix.field.MsgType.ORDER_SINGLE);
// send a pending new
Expand Down Expand Up @@ -104,7 +104,7 @@ public void testReplaceUpdatesOrderRecord(Instrument inInstrument)
OrderStatus.New);
// replace this order
OrderReplace replace1 = Factory.getInstance().createOrderReplace((ExecutionReport)waitForClientReport());
client.sendOrder(replace1);
tradeClient.sendOrder(replace1);
quickfix.Message receivedReplace1 = waitForAndVerifySenderMessage(sender1,
quickfix.field.MsgType.ORDER_CANCEL_REPLACE_REQUEST);
verifyOpenOrders(Sets.newHashSet(order1.getOrderID()));
Expand Down Expand Up @@ -141,7 +141,7 @@ public void testReplaceUpdatesOrderRecord(Instrument inInstrument)
OrderStatus.Replaced);
// replace again
OrderReplace replace2 = Factory.getInstance().createOrderReplace((ExecutionReport)waitForClientReport());
client.sendOrder(replace2);
tradeClient.sendOrder(replace2);
quickfix.Message receivedReplace2 = waitForAndVerifySenderMessage(sender1,
quickfix.field.MsgType.ORDER_CANCEL_REPLACE_REQUEST);
verifyOpenOrders(Sets.newHashSet(replace1.getOrderID()));
Expand Down Expand Up @@ -208,7 +208,7 @@ public void testReplaceUpdatesOrderRecord(Instrument inInstrument)
order2.setPrice(order2Price);
order2.setQuantity(order2Qty);
order2.setSide(Side.Buy);
client.sendOrder(order2);
tradeClient.sendOrder(order2);
quickfix.Message receivedOrder2 = waitForAndVerifySenderMessage(sender1,
quickfix.field.MsgType.ORDER_SINGLE);
// send a pending new
Expand Down
2 changes: 1 addition & 1 deletion dare/src/test/java/org/marketcetera/ors/PositionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ private OrderSingle generatePosition(Instrument inInstrument,
order.setPrice(orderPrice);
order.setQuantity(inOrderQty);
order.setSide(Side.Buy);
client.sendOrder(order);
tradeClient.sendOrder(order);
quickfix.Message receivedOrder = waitForAndVerifySenderMessage(sender,
quickfix.field.MsgType.ORDER_SINGLE);
// send a pending new
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ private OrderSingle sendOrder(BrokerID inBrokerId)
order.setPrice(orderPrice);
order.setQuantity(BigDecimal.TEN);
order.setSide(Side.Buy);
client.sendOrder(order);
tradeClient.sendOrder(order);
return order;
}
/**
Expand Down
38 changes: 22 additions & 16 deletions dare/src/test/java/org/marketcetera/test/DareTestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.junit.Rule;
import org.junit.rules.TestName;
import org.junit.runner.RunWith;
import org.marketcetera.admin.HasCurrentUser;
import org.marketcetera.admin.User;
import org.marketcetera.admin.dao.PersistentPermissionDao;
import org.marketcetera.admin.service.AuthorizationService;
Expand Down Expand Up @@ -83,8 +84,7 @@
import org.marketcetera.trade.Side;
import org.marketcetera.trade.TradeMessage;
import org.marketcetera.trade.TradeMessageListener;
import org.marketcetera.trade.client.DirectTradeClientFactory;
import org.marketcetera.trade.client.DirectTradeClientParameters;
import org.marketcetera.trade.client.DirectTradeClient;
import org.marketcetera.trade.client.TradeClient;
import org.marketcetera.trade.dao.ExecutionReportDao;
import org.marketcetera.trade.dao.OrderSummaryDao;
Expand Down Expand Up @@ -154,10 +154,21 @@ public void setup()
eventBusService.register(this);
fixSettingsProvider = fixSettingsProviderFactory.create();
traderUser = userService.findByName("trader");
DirectTradeClientParameters tradeClientParameters = new DirectTradeClientParameters();
tradeClientParameters.setUsername(traderUser.getName());
client = tradeClientFactory.create(tradeClientParameters);
client.start();
tradeClient = new DirectTradeClient();
PlatformServices.autowire(tradeClient,
applicationContext);
((DirectTradeClient)tradeClient).setCurrentUser(new HasCurrentUser() {
@Override
public User getUser()
{
return traderUser;
}
@Override
public void setUser(User inUser)
{
throw new UnsupportedOperationException();
}}
);
reports.clear();
tradeMessageListener = new TradeMessageListener() {
@Override
Expand All @@ -169,7 +180,7 @@ public void receiveTradeMessage(TradeMessage inTradeMessage)
}
}
};
client.addTradeMessageListener(tradeMessageListener);
tradeClient.addTradeMessageListener(tradeMessageListener);
hostAcceptorPort = fixSettingsProvider.getAcceptorPort();
remoteAcceptorPort = hostAcceptorPort + 1000;
asyncExecutorService = Executors.newCachedThreadPool();
Expand All @@ -193,9 +204,9 @@ public void cleanup()
SLF4JLoggerProxy.info(this,
"{} cleanup beginning",
name.getMethodName());
if(client != null) {
client.removeTradeMessageListener(tradeMessageListener);
client.stop();
if(tradeClient != null) {
tradeClient.removeTradeMessageListener(tradeMessageListener);
tradeClient.stop();
}
try {
if(receiver != null) {
Expand Down Expand Up @@ -2911,7 +2922,7 @@ public quickfix.Message waitForAndVerifySenderMessage(quickfix.Message inSenderM
/**
* provides access to client trading services
*/
protected TradeClient client;
protected TradeClient tradeClient;
/**
* provides fix settings
*/
Expand Down Expand Up @@ -3024,11 +3035,6 @@ public quickfix.Message waitForAndVerifySenderMessage(quickfix.Message inSenderM
*/
@Autowired
protected ApplicationContext applicationContext;
/**
* creates Direct Trade client objects
*/
@Autowired
protected DirectTradeClientFactory tradeClientFactory;
/**
* transaction manager value
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
* @version $Id$
* @since 1.0.0
*/
public abstract class MarketDataModuleTestBase
public abstract class NewMarketDataModuleTestBase
extends ModuleTestBase
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @since 1.0.0
*/
public abstract class SimulatedMarketDataModuleTestBase
extends MarketDataModuleTestBase
extends NewMarketDataModuleTestBase
{
@BeforeClass
public static void setupOnce()
Expand Down
5 changes: 5 additions & 0 deletions modules/marketdata/bogus/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
<!-- Runtime. -->

<!-- Testing. -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>marketdata-core</artifactId>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
import org.marketcetera.marketdata.Capability;
import org.marketcetera.marketdata.Content;
import org.marketcetera.marketdata.MarketDataFeedTestBase;
import org.marketcetera.marketdata.MarketDataModuleTestBase;
import org.marketcetera.marketdata.MarketDataRequestBuilder;
import org.marketcetera.marketdata.NewMarketDataModuleTestBase;
import org.marketcetera.module.DataFlowID;
import org.marketcetera.module.DataRequest;
import org.marketcetera.module.ModuleException;
Expand All @@ -44,7 +44,7 @@
* @since 1.0.0
*/
public class BogusFeedModuleTest
extends MarketDataModuleTestBase
extends NewMarketDataModuleTestBase
{
/**
* Tests a deadlock scenario that occurred for Bogus feed.
Expand Down
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,11 @@
<artifactId>esper-compiler</artifactId>
<version>${esper.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.janino</groupId>
<artifactId>janino</artifactId>
<version>3.1.6</version>
</dependency>
<dependency>
<groupId>com.espertech</groupId>
<artifactId>esper-common-avro</artifactId>
Expand Down

0 comments on commit b61213b

Please sign in to comment.