mirror of
https://github.com/apache/sqoop.git
synced 2025-05-19 02:10:54 +08:00
SQOOP-1816: Sqoop2: Add logging to the test DerbyProvider implementation
(Jarek Jarcec Cecho via Abraham Elmahrek)
This commit is contained in:
parent
39e99cc5f0
commit
6822e8ba3b
@ -17,8 +17,10 @@
|
||||
*/
|
||||
package org.apache.sqoop.common.test.db;
|
||||
|
||||
import org.apache.log4j.Level;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.derby.drda.NetworkServerControl;
|
||||
import org.apache.sqoop.common.test.utils.LoggerWriter;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
||||
@ -40,7 +42,12 @@ public void start() {
|
||||
// Start embedded server
|
||||
try {
|
||||
server = new NetworkServerControl(InetAddress.getByName("localhost"), 1527);
|
||||
server.start(null);
|
||||
server.start(new LoggerWriter(LOG, Level.INFO));
|
||||
|
||||
// Start won't thrown an exception in case that it fails to start, one
|
||||
// have to explicitly call ping() in order to verify if the server is
|
||||
// up. Check DERBY-1465 for more details.
|
||||
server.ping();
|
||||
} catch (Exception e) {
|
||||
LOG.error("Can't start Derby network server", e);
|
||||
throw new RuntimeException("Can't derby server", e);
|
||||
|
@ -0,0 +1,65 @@
|
||||
/**
|
||||
* 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.sqoop.common.test.utils;
|
||||
|
||||
import org.apache.log4j.Level;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.Writer;
|
||||
|
||||
/**
|
||||
* PrintWriter implementation that will forward all the messages into given logger.
|
||||
*/
|
||||
public class LoggerWriter extends PrintWriter {
|
||||
|
||||
public LoggerWriter(final Logger logger, final Level level) {
|
||||
super(new InternalWriter(logger, level));
|
||||
}
|
||||
|
||||
private static class InternalWriter extends Writer {
|
||||
|
||||
private final Logger logger;
|
||||
private final Level level;
|
||||
|
||||
public InternalWriter(final Logger logger, final Level level) {
|
||||
this.logger = logger;
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(char[] chars, int offset, int len) throws IOException {
|
||||
while(len > 0 && (chars[len - 1] == '\n' || chars[len - 1] == '\r')) {
|
||||
len--;
|
||||
}
|
||||
|
||||
if(len > 0) {
|
||||
logger.log(level, String.copyValueOf(chars, offset, len));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() throws IOException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user