Synchronisation now shouldn't fail if the trusted host has no new messages
- fixed tests for Gradle builds - fixed SerializationTest
This commit is contained in:
parent
d67c932fb2
commit
7fb837645f
@ -10,6 +10,19 @@ uploadArchives {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
configurations {
|
||||||
|
testArtifacts.extendsFrom testRuntime
|
||||||
|
}
|
||||||
|
|
||||||
|
task testJar(type: Jar) {
|
||||||
|
classifier = 'test'
|
||||||
|
from sourceSets.test.output
|
||||||
|
}
|
||||||
|
|
||||||
|
artifacts {
|
||||||
|
testArtifacts testJar
|
||||||
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile 'org.slf4j:slf4j-api:1.7.12'
|
compile 'org.slf4j:slf4j-api:1.7.12'
|
||||||
testCompile 'junit:junit:4.11'
|
testCompile 'junit:junit:4.11'
|
||||||
|
@ -18,18 +18,17 @@ package ch.dissem.bitmessage.entity;
|
|||||||
|
|
||||||
import ch.dissem.bitmessage.entity.payload.*;
|
import ch.dissem.bitmessage.entity.payload.*;
|
||||||
import ch.dissem.bitmessage.entity.valueobject.Label;
|
import ch.dissem.bitmessage.entity.valueobject.Label;
|
||||||
import ch.dissem.bitmessage.exception.DecryptionFailedException;
|
|
||||||
import ch.dissem.bitmessage.factory.Factory;
|
import ch.dissem.bitmessage.factory.Factory;
|
||||||
import ch.dissem.bitmessage.utils.TestBase;
|
import ch.dissem.bitmessage.utils.TestBase;
|
||||||
import ch.dissem.bitmessage.utils.TestUtils;
|
import ch.dissem.bitmessage.utils.TestUtils;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.Arrays;
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
import static ch.dissem.bitmessage.entity.Plaintext.Type.MSG;
|
import static ch.dissem.bitmessage.entity.Plaintext.Type.MSG;
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.Assert.*;
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
|
|
||||||
public class SerializationTest extends TestBase {
|
public class SerializationTest extends TestBase {
|
||||||
@Test
|
@Test
|
||||||
@ -87,6 +86,12 @@ public class SerializationTest extends TestBase {
|
|||||||
p1.write(out);
|
p1.write(out);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||||
Plaintext p2 = Plaintext.read(MSG, in);
|
Plaintext p2 = Plaintext.read(MSG, in);
|
||||||
|
|
||||||
|
// Received is automatically set on deserialization, so we'll need to set it to 0
|
||||||
|
Field received = Plaintext.class.getDeclaredField("received");
|
||||||
|
received.setAccessible(true);
|
||||||
|
received.set(p2, 0L);
|
||||||
|
|
||||||
assertEquals(p1, p2);
|
assertEquals(p1, p2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,6 +100,7 @@ public class SerializationTest extends TestBase {
|
|||||||
InputStream in = new ByteArrayInputStream(data);
|
InputStream in = new ByteArrayInputStream(data);
|
||||||
ObjectMessage object = Factory.getObjectMessage(version, in, data.length);
|
ObjectMessage object = Factory.getObjectMessage(version, in, data.length);
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
|
assertNotNull(object);
|
||||||
object.write(out);
|
object.write(out);
|
||||||
assertArrayEquals(data, out.toByteArray());
|
assertArrayEquals(data, out.toByteArray());
|
||||||
assertEquals(expectedPayloadType.getCanonicalName(), object.getPayload().getClass().getCanonicalName());
|
assertEquals(expectedPayloadType.getCanonicalName(), object.getPayload().getClass().getCanonicalName());
|
||||||
@ -105,7 +111,7 @@ public class SerializationTest extends TestBase {
|
|||||||
Plaintext plaintext = new Plaintext.Builder(MSG)
|
Plaintext plaintext = new Plaintext.Builder(MSG)
|
||||||
.from(TestUtils.loadContact())
|
.from(TestUtils.loadContact())
|
||||||
.to(TestUtils.loadIdentity("BM-2cSqjfJ8xK6UUn5Rw3RpdGQ9RsDkBhWnS8"))
|
.to(TestUtils.loadIdentity("BM-2cSqjfJ8xK6UUn5Rw3RpdGQ9RsDkBhWnS8"))
|
||||||
.labels(Arrays.asList(new Label("Test", Label.Type.INBOX, 0)))
|
.labels(Collections.singletonList(new Label("Test", Label.Type.INBOX, 0)))
|
||||||
.message("Test", "Test Test.\nTest")
|
.message("Test", "Test Test.\nTest")
|
||||||
.build();
|
.build();
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
|
@ -15,5 +15,6 @@ dependencies {
|
|||||||
testCompile 'junit:junit:4.11'
|
testCompile 'junit:junit:4.11'
|
||||||
testCompile 'org.slf4j:slf4j-simple:1.7.12'
|
testCompile 'org.slf4j:slf4j-simple:1.7.12'
|
||||||
testCompile 'org.mockito:mockito-core:1.10.19'
|
testCompile 'org.mockito:mockito-core:1.10.19'
|
||||||
|
testCompile project(path: ':domain', configuration: 'testArtifacts')
|
||||||
testCompile project(':security-bc')
|
testCompile project(':security-bc')
|
||||||
}
|
}
|
@ -25,7 +25,6 @@ import ch.dissem.bitmessage.exception.InsufficientProofOfWorkException;
|
|||||||
import ch.dissem.bitmessage.exception.NodeException;
|
import ch.dissem.bitmessage.exception.NodeException;
|
||||||
import ch.dissem.bitmessage.factory.Factory;
|
import ch.dissem.bitmessage.factory.Factory;
|
||||||
import ch.dissem.bitmessage.ports.NetworkHandler.MessageListener;
|
import ch.dissem.bitmessage.ports.NetworkHandler.MessageListener;
|
||||||
import ch.dissem.bitmessage.utils.DebugUtils;
|
|
||||||
import ch.dissem.bitmessage.utils.UnixTime;
|
import ch.dissem.bitmessage.utils.UnixTime;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -70,6 +69,7 @@ public class Connection implements Runnable {
|
|||||||
private OutputStream out;
|
private OutputStream out;
|
||||||
private int version;
|
private int version;
|
||||||
private long[] streams;
|
private long[] streams;
|
||||||
|
private int readTimeoutCounter;
|
||||||
|
|
||||||
public Connection(InternalContext context, Mode mode, Socket socket, MessageListener listener,
|
public Connection(InternalContext context, Mode mode, Socket socket, MessageListener listener,
|
||||||
ConcurrentMap<InventoryVector, Long> requestedObjectsMap) throws IOException {
|
ConcurrentMap<InventoryVector, Long> requestedObjectsMap) throws IOException {
|
||||||
@ -185,6 +185,7 @@ public class Connection implements Runnable {
|
|||||||
} catch (SocketTimeoutException ignore) {
|
} catch (SocketTimeoutException ignore) {
|
||||||
if (state == ACTIVE) {
|
if (state == ACTIVE) {
|
||||||
sendQueue();
|
sendQueue();
|
||||||
|
if (syncFinished(null)) disconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -205,7 +206,13 @@ public class Connection implements Runnable {
|
|||||||
if (syncTimeout < UnixTime.now()) {
|
if (syncTimeout < UnixTime.now()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!(msg.getPayload() instanceof Addr) && requestedObjects.isEmpty() && sendingQueue.isEmpty()) {
|
if (msg == null) {
|
||||||
|
readTimeoutCounter++;
|
||||||
|
return readTimeoutCounter > 1;
|
||||||
|
}
|
||||||
|
readTimeoutCounter = 0;
|
||||||
|
if (!(msg.getPayload() instanceof Addr) && !(msg.getPayload() instanceof GetData)
|
||||||
|
&& requestedObjects.isEmpty() && sendingQueue.isEmpty()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -311,9 +318,9 @@ public class Connection implements Runnable {
|
|||||||
ctx.getNetworkHandler().offer(objectMessage.getInventoryVector());
|
ctx.getNetworkHandler().offer(objectMessage.getInventoryVector());
|
||||||
} catch (InsufficientProofOfWorkException e) {
|
} catch (InsufficientProofOfWorkException e) {
|
||||||
LOG.warn(e.getMessage());
|
LOG.warn(e.getMessage());
|
||||||
|
// DebugUtils.saveToFile(objectMessage); // this line must not be committed active
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOG.error("Stream " + objectMessage.getStream() + ", object type " + objectMessage.getType() + ": " + e.getMessage(), e);
|
LOG.error("Stream " + objectMessage.getStream() + ", object type " + objectMessage.getType() + ": " + e.getMessage(), e);
|
||||||
DebugUtils.saveToFile(objectMessage);
|
|
||||||
} finally {
|
} finally {
|
||||||
requestedObjects.remove(objectMessage.getInventoryVector());
|
requestedObjects.remove(objectMessage.getInventoryVector());
|
||||||
}
|
}
|
||||||
|
@ -122,7 +122,7 @@ public class NetworkHandlerTest {
|
|||||||
assertEquals(2, peerInventory.getInventory().size());
|
assertEquals(2, peerInventory.getInventory().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeout = 5_000)
|
@Test(timeout = 10_000)
|
||||||
public void ensureObjectsAreSynchronizedIfOnlyNodeHasObjects() throws Exception {
|
public void ensureObjectsAreSynchronizedIfOnlyNodeHasObjects() throws Exception {
|
||||||
peerInventory.init();
|
peerInventory.init();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user