Calculate the timestamp outside the subscription/transport update

writer - this will allow it to be saved so new connections can work
out whether they should send updates.
This commit is contained in:
akwizgran
2011-08-14 13:36:21 +02:00
parent 4497774311
commit 2c13e35dc4
9 changed files with 31 additions and 27 deletions

View File

@@ -64,7 +64,7 @@ public class FileReadWriteTest extends TestCase {
private final File file = new File(testDir, "foo");
private final BatchId ack = new BatchId(TestUtils.getRandomId());
private final long start = System.currentTimeMillis();
private final long timestamp = System.currentTimeMillis();
private final PacketReaderFactory packetReaderFactory;
private final PacketWriterFactory packetWriterFactory;
@@ -172,11 +172,11 @@ public class FileReadWriteTest extends TestCase {
Map<Group, Long> subs = new LinkedHashMap<Group, Long>();
subs.put(group, 0L);
subs.put(group1, 0L);
s.writeSubscriptions(subs);
s.writeSubscriptionUpdate(subs, timestamp);
packetWriter.finishPacket();
TransportWriter t = protocolWriterFactory.createTransportWriter(out);
t.writeTransports(transports);
t.writeTransportUpdate(transports, timestamp);
packetWriter.finishPacket();
out.flush();
@@ -257,16 +257,14 @@ public class FileReadWriteTest extends TestCase {
assertEquals(2, subs.size());
assertEquals(Long.valueOf(0L), subs.get(group));
assertEquals(Long.valueOf(0L), subs.get(group1));
assertTrue(s.getTimestamp() > start);
assertTrue(s.getTimestamp() <= System.currentTimeMillis());
assertTrue(s.getTimestamp() == timestamp);
// Read the transport update
assertTrue(protocolReader.hasTransportUpdate());
TransportUpdate t = protocolReader.readTransportUpdate();
packetReader.finishPacket();
assertEquals(transports, t.getTransports());
assertTrue(t.getTimestamp() > start);
assertTrue(t.getTimestamp() <= System.currentTimeMillis());
assertTrue(t.getTimestamp() == timestamp);
in.close();
}

View File

@@ -779,8 +779,9 @@ public abstract class DatabaseComponentTest extends TestCase {
oneOf(database).getVisibleSubscriptions(txn, contactId);
will(returnValue(Collections.singletonMap(group, 0L)));
// Add the subscriptions to the writer
oneOf(subscriptionWriter).writeSubscriptions(
Collections.singletonMap(group, 0L));
oneOf(subscriptionWriter).writeSubscriptionUpdate(
with(Collections.singletonMap(group, 0L)),
with(any(long.class)));
}});
DatabaseComponent db = createDatabaseComponent(database, cleaner);
@@ -811,7 +812,8 @@ public abstract class DatabaseComponentTest extends TestCase {
oneOf(database).getTransports(txn);
will(returnValue(transports));
// Add the properties to the writer
oneOf(transportWriter).writeTransports(transports);
oneOf(transportWriter).writeTransportUpdate(with(transports),
with(any(long.class)));
}});
DatabaseComponent db = createDatabaseComponent(database, cleaner);

View File

@@ -51,6 +51,7 @@ public class ProtocolReadWriteTest extends TestCase {
private final BitSet bitSet;
private final Map<Group, Long> subscriptions;
private final Map<String, Map<String, String>> transports;
private final long timestamp = System.currentTimeMillis();
public ProtocolReadWriteTest() throws Exception {
super();
@@ -75,8 +76,6 @@ public class ProtocolReadWriteTest extends TestCase {
@Test
public void testWriteAndRead() throws Exception {
long start = System.currentTimeMillis();
// Write
ByteArrayOutputStream out = new ByteArrayOutputStream();
@@ -96,10 +95,10 @@ public class ProtocolReadWriteTest extends TestCase {
r.writeRequest(offerId, bitSet, 10);
SubscriptionWriter s = writerFactory.createSubscriptionWriter(out);
s.writeSubscriptions(subscriptions);
s.writeSubscriptionUpdate(subscriptions, timestamp);
TransportWriter t = writerFactory.createTransportWriter(out);
t.writeTransports(transports);
t.writeTransportUpdate(transports, timestamp);
// Read
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
@@ -120,10 +119,10 @@ public class ProtocolReadWriteTest extends TestCase {
SubscriptionUpdate subscriptionUpdate = reader.readSubscriptionUpdate();
assertEquals(subscriptions, subscriptionUpdate.getSubscriptions());
assertTrue(subscriptionUpdate.getTimestamp() >= start);
assertTrue(subscriptionUpdate.getTimestamp() == timestamp);
TransportUpdate transportUpdate = reader.readTransportUpdate();
assertEquals(transports, transportUpdate.getTransports());
assertTrue(transportUpdate.getTimestamp() >= start);
assertTrue(transportUpdate.getTimestamp() == timestamp);
}
}