}
@Test(groups = { UNIT })
public synchronized void synchronizeLog() throws Exception {
final LogDescriptor range = new LogDescriptor("gwID", 1, new SortedRangeSet(new long[] {0}));
final LogEvent event = new LogEvent("gwID", 1, 1, 1, 1, new Properties());
final List<LogEvent> events = new ArrayList<LogEvent>();
events.add(event);
InputStream input = new InputStream() {
byte[] bytes = range.toRepresentation().getBytes();
int count = 0;
@Override
public int read() throws IOException {
if (count < bytes.length) {
byte b = bytes[count];
count++;
return b;
} else {
return -1;
}
}
};
TestUtils.configureObject(m_task, LogStore.class, new LogStore() {
public List<?> get(long logID, long from, long to) throws IOException {
return events;
}
public long getHighestID(long logID) throws IOException {
return event.getID();
}
public List<?> get(long logID) throws IOException { return null; }
public long[] getLogIDs() throws IOException { return null; }
@SuppressWarnings("unchecked")
public LogEvent put(int type, Dictionary props) throws IOException { return null; }
});
MockConnection connection = new MockConnection(new URL("http://mock"));
m_task.synchronizeLog(1, input, connection);
String expectedString = event.toRepresentation() + "\n";
String actualString = connection.getString();
assert actualString.equals(expectedString) : "We expected " + expectedString + " but received " + actualString;
}