Skip to content

Commit

Permalink
Catch an UnknownHostException and log the 'unknown' host. Also change…
Browse files Browse the repository at this point in the history
…d the log4j.xml in the test resources to NOT turn off logging for the data loader. Instead turned off logging in the unit test that really cared.
  • Loading branch information
chenson42 committed Oct 26, 2007
1 parent 3a3ffae commit fc7f197
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 38 deletions.
Expand Up @@ -25,6 +25,7 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ConnectException;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -112,6 +113,8 @@ protected List<IncomingBatchHistory> loadDataAndReturnBatches(
}
} catch (ConnectException ex) {
logger.warn(ErrorConstants.COULD_NOT_CONNECT_TO_TRANSPORT);
} catch (UnknownHostException ex) {
logger.warn(ErrorConstants.COULD_NOT_CONNECT_TO_TRANSPORT + " Unknown host name of " + ex.getMessage());
} catch (RegistrationNotOpenException ex) {
logger.warn("Registration attempt failed. Registration was not open for the node.");
} catch (Exception e) {
Expand Down
Expand Up @@ -33,26 +33,28 @@
import org.jumpmind.symmetric.service.IPullService;

public class PullService implements IPullService {

private static final Log logger = LogFactory.getLog(PullService.class);

private INodeService nodeService;

private IDataLoaderService dataLoaderService;

public void pullData() {
logger.info("Pull requested");
List<Node> nodes = nodeService.findNodesToPull();
for (Node node : nodes) {
try {
dataLoaderService.loadData(node, nodeService.findIdentity());
} catch (ConnectException ex) {
logger.warn(ErrorConstants.COULD_NOT_CONNECT_TO_TRANSPORT);
} catch (IOException e) {
logger.error(e, e);
if (nodes != null && nodes.size() > 0) {
logger.info("Pull requested");
for (Node node : nodes) {
try {
dataLoaderService.loadData(node, nodeService.findIdentity());
} catch (ConnectException ex) {
logger.warn(ErrorConstants.COULD_NOT_CONNECT_TO_TRANSPORT);
} catch (IOException e) {
logger.error(e, e);
}
}
logger.info("Pull completed");
}
logger.info("Pull completed");
}

public void setNodeService(INodeService nodeService) {
Expand Down
Expand Up @@ -56,7 +56,7 @@ public class PurgeService extends AbstractService implements IPurgeService {
private int retentionInMinutes = 7200;

public void purge() {
logger.info("The symmetric purge process is about to run.");
logger.info("The purge process is about to run.");
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.MINUTE, -retentionInMinutes);
for (String sql : purgeSql) {
Expand Down
Expand Up @@ -54,14 +54,14 @@ public void setExtractor(IDataExtractorService extractor) {
}

public void pushData() {
info("Push requested");
List<Node> nodes = nodeService.findNodesToPushTo();
if (nodes != null) {
if (nodes != null && nodes.size() > 0) {
info("Push requested");
for (Node node : nodes) {
pushToNode(node);
}
}
info("Push request completed");
info("Push request completed");
}
}

class ParameterParser {
Expand Down
Expand Up @@ -43,8 +43,6 @@

/**
* Allow remote communication to nodes, in order to push data, pull data, and send messages.
*
* @author elong
*/
public class HttpTransportManager extends AbstractTransportManager implements
ITransportManager {
Expand Down
Expand Up @@ -26,13 +26,16 @@
import java.util.List;

import org.apache.commons.lang.ArrayUtils;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.jumpmind.symmetric.common.Constants;
import org.jumpmind.symmetric.common.TestConstants;
import org.jumpmind.symmetric.common.csv.CsvConstants;
import org.jumpmind.symmetric.load.AbstractDataLoaderTest;
import org.jumpmind.symmetric.model.Node;
import org.jumpmind.symmetric.load.csv.CsvLoader;
import org.jumpmind.symmetric.model.IncomingBatch;
import org.jumpmind.symmetric.model.IncomingBatchHistory;
import org.jumpmind.symmetric.model.Node;
import org.jumpmind.symmetric.service.IDataLoaderService;
import org.jumpmind.symmetric.service.IIncomingBatchService;
import org.jumpmind.symmetric.transport.internal.InternalIncomingTransport;
Expand All @@ -53,11 +56,16 @@ public class DataLoaderServiceTest extends AbstractDataLoaderTest {

protected Node client;

protected void turnOffLoggingForTest() {
Logger.getLogger(DataLoaderService.class).setLevel(Level.OFF);
Logger.getLogger(CsvLoader.class).setLevel(Level.OFF);
}

@BeforeTest(groups = "continuous")
protected void setUp() {
turnOffLoggingForTest();
dataLoaderService = (IDataLoaderService) getBeanFactory().getBean(Constants.DATALOADER_SERVICE);
incomingBatchService = (IIncomingBatchService) getBeanFactory().getBean(
Constants.INCOMING_BATCH_SERVICE);
incomingBatchService = (IIncomingBatchService) getBeanFactory().getBean(Constants.INCOMING_BATCH_SERVICE);
transportManager = new MockTransportManager();
dataLoaderService.setTransportManager(transportManager);
client = new Node();
Expand Down Expand Up @@ -154,8 +162,8 @@ public void testSkippingResentBatch() throws Exception {

@Test(groups = "continuous")
public void testErrorWhileSkip() throws Exception {
String[] values = { getNextId(), "string2", "string not null2", "char2", "char not null2",
"2007-01-02", "2007-02-03 04:05:06.0", "0", "47", "67.89" };
String[] values = { getNextId(), "string2", "string not null2", "char2", "char not null2", "2007-01-02",
"2007-02-03 04:05:06.0", "0", "47", "67.89" };

testSimple(CsvConstants.INSERT, values, values);
Assert.assertEquals(findIncomingBatchStatus(batchId, TestConstants.TEST_CLIENT_EXTERNAL_ID),
Expand Down Expand Up @@ -189,8 +197,8 @@ public void testErrorWhileSkip() throws Exception {

@Test(groups = "continuous")
public void testErrorWhileParsing() throws Exception {
String[] values = { getNextId(), "should not reach database", "string not null", "char",
"char not null", "2007-01-02", "2007-02-03 04:05:06.0", "0", "47", "67.89" };
String[] values = { getNextId(), "should not reach database", "string not null", "char", "char not null",
"2007-01-02", "2007-02-03 04:05:06.0", "0", "47", "67.89" };

ByteArrayOutputStream out = new ByteArrayOutputStream();
CsvWriter writer = getWriter(out);
Expand All @@ -215,8 +223,8 @@ public void testErrorWhileParsing() throws Exception {
@Test(groups = "continuous")
public void testErrorThenSuccessBatch() throws Exception {
String[] values = { getNextId(), "This string is too large and will cause the statement to fail",
"string not null2", "char2", "char not null2", "2007-01-02", "2007-02-03 04:05:06.0", "0",
"47", "67.89" };
"string not null2", "char2", "char not null2", "2007-01-02", "2007-02-03 04:05:06.0", "0", "47",
"67.89" };
getNextBatchId();
int retries = 3;
for (int i = 0; i < retries; i++) {
Expand Down Expand Up @@ -249,11 +257,11 @@ public void testErrorThenSuccessBatch() throws Exception {

@Test(groups = "continuous")
public void testMultipleBatch() throws Exception {
String[] values = { getNextId(), "string", "string not null2", "char2", "char not null2",
"2007-01-02", "2007-02-03 04:05:06.0", "0", "47", "67.89" };
String[] values = { getNextId(), "string", "string not null2", "char2", "char not null2", "2007-01-02",
"2007-02-03 04:05:06.0", "0", "47", "67.89" };
String[] values2 = { getNextId(), "This string is too large and will cause the statement to fail",
"string not null2", "char2", "char not null2", "2007-01-02", "2007-02-03 04:05:06.0", "0",
"47", "67.89" };
"string not null2", "char2", "char not null2", "2007-01-02", "2007-02-03 04:05:06.0", "0", "47",
"67.89" };

ByteArrayOutputStream out = new ByteArrayOutputStream();
CsvWriter writer = getWriter(out);
Expand Down
8 changes: 0 additions & 8 deletions symmetric/src/test/resources/log4j.xml
Expand Up @@ -17,14 +17,6 @@
<priority value="INFO" />
</category>

<category name="org.jumpmind.symmetric.service.impl.DataLoaderService">
<priority value="OFF" />
</category>

<category name="org.jumpmind.symmetric.load.csv.CsvLoader">
<priority value="OFF" />
</category>

<category name="org.springframework.jdbc">
<priority value="WARN" />
</category>
Expand Down

0 comments on commit fc7f197

Please sign in to comment.