mirror of https://github.com/zlatinb/muwire
update tests to recent api changes
parent
fe35316c1f
commit
90988ce717
|
@ -23,7 +23,11 @@ class SimpleHostCache extends HostCache {
|
|||
final int interval
|
||||
final Timer timer
|
||||
final Map<Destination, Host> hosts = Collections.synchronizedMap(new HashMap<>())
|
||||
|
||||
|
||||
SimpleHostCache() {
|
||||
super(null,null,null)
|
||||
}
|
||||
|
||||
public SimpleHostCache(TrustService trustService, File storage, int interval,
|
||||
MuWireSettings settings, Destination myself) {
|
||||
super(trustService, settings, myself)
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.muwire.core.connection
|
||||
|
||||
import com.muwire.core.hostcache.SimpleHostCache
|
||||
|
||||
import static org.junit.Assert.fail
|
||||
|
||||
import java.util.concurrent.CopyOnWriteArrayList
|
||||
|
@ -56,7 +58,7 @@ class ConnectionAcceptorTest {
|
|||
void before() {
|
||||
connectionManagerMock = new MockFor(UltrapeerConnectionManager.class)
|
||||
i2pAcceptorMock = new MockFor(I2PAcceptor.class)
|
||||
hostCacheMock = new MockFor(HostCache.class)
|
||||
hostCacheMock = new MockFor(SimpleHostCache.class)
|
||||
trustServiceMock = new MockFor(TrustService.class)
|
||||
searchManagerMock = new MockFor(SearchManager.class)
|
||||
uploadManagerMock = new MockFor(UploadManager.class)
|
||||
|
@ -95,7 +97,7 @@ class ConnectionAcceptorTest {
|
|||
connectionEstablisher = connectionEstablisherMock.proxyInstance()
|
||||
|
||||
acceptor = new ConnectionAcceptor(eventBus, connectionManager, settings, i2pAcceptor,
|
||||
hostCache, trustService, searchManager, uploadManager, null, connectionEstablisher, null, null)
|
||||
hostCache, trustService, searchManager, uploadManager, null, connectionEstablisher, null, null, null)
|
||||
acceptor.start()
|
||||
Thread.sleep(100)
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.muwire.core.connection
|
||||
|
||||
import com.muwire.core.hostcache.SimpleHostCache
|
||||
|
||||
import java.util.concurrent.CopyOnWriteArrayList
|
||||
|
||||
import org.junit.After
|
||||
|
@ -55,7 +57,7 @@ class ConnectionEstablisherTest {
|
|||
eventBus.register(HostDiscoveredEvent.class, listener)
|
||||
i2pConnectorMock = new MockFor(I2PConnector.class)
|
||||
connectionManagerMock = new MockFor(ConnectionManager.class)
|
||||
hostCacheMock = new MockFor(HostCache.class)
|
||||
hostCacheMock = new MockFor(SimpleHostCache.class)
|
||||
}
|
||||
|
||||
@After
|
||||
|
@ -83,7 +85,7 @@ class ConnectionEstablisherTest {
|
|||
connectionManagerMock.ignore.needsConnections {
|
||||
true
|
||||
}
|
||||
hostCacheMock.ignore.getHosts { num ->
|
||||
hostCacheMock.ignore.getHosts { num, filter ->
|
||||
assert num == 1
|
||||
[destinations.dest1]
|
||||
}
|
||||
|
@ -113,7 +115,7 @@ class ConnectionEstablisherTest {
|
|||
connectionManagerMock.ignore.needsConnections {
|
||||
true
|
||||
}
|
||||
hostCacheMock.ignore.getHosts { num ->
|
||||
hostCacheMock.ignore.getHosts { num, filter ->
|
||||
assert num == 1
|
||||
[destinations.dest1]
|
||||
}
|
||||
|
@ -156,7 +158,7 @@ class ConnectionEstablisherTest {
|
|||
connectionManagerMock.ignore.needsConnections {
|
||||
true
|
||||
}
|
||||
hostCacheMock.ignore.getHosts { num ->
|
||||
hostCacheMock.ignore.getHosts { num, filter ->
|
||||
assert num == 1
|
||||
[destinations.dest1]
|
||||
}
|
||||
|
@ -198,7 +200,7 @@ class ConnectionEstablisherTest {
|
|||
connectionManagerMock.ignore.needsConnections {
|
||||
true
|
||||
}
|
||||
hostCacheMock.ignore.getHosts { num ->
|
||||
hostCacheMock.ignore.getHosts { num, filter ->
|
||||
assert num == 1
|
||||
[destinations.dest1]
|
||||
}
|
||||
|
@ -241,7 +243,7 @@ class ConnectionEstablisherTest {
|
|||
connectionManagerMock.ignore.needsConnections {
|
||||
true
|
||||
}
|
||||
hostCacheMock.ignore.getHosts { num ->
|
||||
hostCacheMock.ignore.getHosts { num, filter ->
|
||||
assert num == 1
|
||||
[destinations.dest1]
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ class DownloadSessionTest {
|
|||
eventBus = new EventBus()
|
||||
}
|
||||
|
||||
private void initSession(int size, def claimedPieces = [], boolean browse = false, boolean feed = false, boolean chat = false) {
|
||||
private void initSession(int size, def claimedPieces = [], boolean browse = false, boolean feed = false, boolean chat = false, boolean message = false) {
|
||||
Random r = new Random()
|
||||
byte [] content = new byte[size]
|
||||
r.nextBytes(content)
|
||||
|
@ -79,7 +79,7 @@ class DownloadSessionTest {
|
|||
endpoint = new Endpoint(null, fromUploader, toUploader, null)
|
||||
|
||||
session = new DownloadSession(eventBus, "",pieces, infoHash, endpoint, target, pieceSize, size, available, new AtomicLong(),
|
||||
browse, feed, chat)
|
||||
browse, feed, chat, message)
|
||||
downloadThread = new Thread( { perform() } as Runnable)
|
||||
downloadThread.setDaemon(true)
|
||||
downloadThread.start()
|
||||
|
|
|
@ -26,7 +26,7 @@ class HasherServiceTest {
|
|||
eventBus = new EventBus()
|
||||
hasher = new FileHasher()
|
||||
def props = new MuWireSettings()
|
||||
service = new HasherService(hasher, eventBus, new FileManager(eventBus, props), props)
|
||||
service = new HasherService(eventBus, new FileManager(eventBus, props), props)
|
||||
eventBus.register(FileHashedEvent.class, listener)
|
||||
eventBus.register(FileSharedEvent.class, service)
|
||||
service.start()
|
||||
|
|
|
@ -18,8 +18,11 @@ import groovy.mock.interceptor.MockFor
|
|||
import groovy.mock.interceptor.StubFor
|
||||
import net.i2p.data.Destination
|
||||
|
||||
import java.util.function.Predicate
|
||||
|
||||
class HostCacheTest {
|
||||
|
||||
def filter = {true} as Predicate
|
||||
|
||||
File persist
|
||||
HostCache cache
|
||||
|
@ -61,7 +64,7 @@ class HostCacheTest {
|
|||
@Test
|
||||
void testEmpty() {
|
||||
initMocks()
|
||||
assert cache.getHosts(5).size() == 0
|
||||
assert cache.getHosts(5, filter).size() == 0
|
||||
assert cache.getGoodHosts(5).size() == 0
|
||||
}
|
||||
|
||||
|
@ -81,7 +84,7 @@ class HostCacheTest {
|
|||
|
||||
cache.onHostDiscoveredEvent(new HostDiscoveredEvent(destination: destinations.dest1))
|
||||
|
||||
def rv = cache.getHosts(5)
|
||||
def rv = cache.getHosts(5, filter)
|
||||
assert rv.size() == 1
|
||||
assert rv.contains(destinations.dest1)
|
||||
|
||||
|
@ -103,7 +106,7 @@ class HostCacheTest {
|
|||
initMocks()
|
||||
|
||||
cache.onHostDiscoveredEvent(new HostDiscoveredEvent(destination: destinations.dest1))
|
||||
assert cache.getHosts(5).size() == 0
|
||||
assert cache.getHosts(5, filter).size() == 0
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -121,7 +124,7 @@ class HostCacheTest {
|
|||
initMocks()
|
||||
|
||||
cache.onHostDiscoveredEvent(new HostDiscoveredEvent(destination: destinations.dest1))
|
||||
assert cache.getHosts(5).size() == 0
|
||||
assert cache.getHosts(5, filter).size() == 0
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -145,7 +148,7 @@ class HostCacheTest {
|
|||
cache.onHostDiscoveredEvent(new HostDiscoveredEvent(destination: destinations.dest1))
|
||||
cache.onHostDiscoveredEvent(new HostDiscoveredEvent(destination: destinations.dest2))
|
||||
|
||||
def rv = cache.getHosts(1)
|
||||
def rv = cache.getHosts(1, filter)
|
||||
assert rv.size() == 1
|
||||
assert rv.contains(destinations.dest1) || rv.contains(destinations.dest2)
|
||||
}
|
||||
|
@ -174,7 +177,7 @@ class HostCacheTest {
|
|||
cache.onConnectionEvent( new ConnectionEvent(endpoint: endpoint, status: ConnectionAttemptStatus.FAILED))
|
||||
cache.onConnectionEvent( new ConnectionEvent(endpoint: endpoint, status: ConnectionAttemptStatus.FAILED))
|
||||
|
||||
assert cache.getHosts(5).size() == 0
|
||||
assert cache.getHosts(5, filter).size() == 0
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -198,7 +201,7 @@ class HostCacheTest {
|
|||
cache.onConnectionEvent( new ConnectionEvent(endpoint: endpoint, status: ConnectionAttemptStatus.FAILED))
|
||||
cache.onConnectionEvent( new ConnectionEvent(endpoint: endpoint, status: ConnectionAttemptStatus.SUCCESSFUL))
|
||||
|
||||
def rv = cache.getHosts(5)
|
||||
def rv = cache.getHosts(5, filter)
|
||||
assert rv.size() == 1
|
||||
assert rv.contains(destinations.dest1)
|
||||
|
||||
|
@ -225,7 +228,7 @@ class HostCacheTest {
|
|||
def endpoint = new Endpoint(destinations.dest1, null, null, null)
|
||||
cache.onConnectionEvent( new ConnectionEvent(endpoint: endpoint, status: ConnectionAttemptStatus.SUCCESSFUL))
|
||||
|
||||
def rv = cache.getHosts(5)
|
||||
def rv = cache.getHosts(5, filter)
|
||||
def rv2 = cache.getGoodHosts(5)
|
||||
assert rv.size() == 1
|
||||
assert rv.contains(destinations.dest1)
|
||||
|
@ -233,7 +236,7 @@ class HostCacheTest {
|
|||
|
||||
cache.onConnectionEvent( new ConnectionEvent(endpoint: endpoint, status: ConnectionAttemptStatus.FAILED))
|
||||
|
||||
rv = cache.getHosts(5)
|
||||
rv = cache.getHosts(5, filter)
|
||||
assert rv.size() == 1
|
||||
assert rv.contains(destinations.dest1)
|
||||
assert cache.getGoodHosts(5).size() == 0
|
||||
|
@ -259,7 +262,7 @@ class HostCacheTest {
|
|||
cache.onHostDiscoveredEvent(new HostDiscoveredEvent(destination: destinations.dest1))
|
||||
cache.onHostDiscoveredEvent(new HostDiscoveredEvent(destination: destinations.dest1))
|
||||
|
||||
def rv = cache.getHosts(5)
|
||||
def rv = cache.getHosts(5, filter)
|
||||
assert rv.size() == 1
|
||||
assert rv.contains(destinations.dest1)
|
||||
}
|
||||
|
@ -313,7 +316,7 @@ class HostCacheTest {
|
|||
settingsMock.ignore.getHostHopelessPurgeInterval { 0 }
|
||||
|
||||
initMocks()
|
||||
def rv = cache.getHosts(5)
|
||||
def rv = cache.getHosts(5, filter)
|
||||
assert rv.size() == 1
|
||||
assert rv.contains(destinations.dest1)
|
||||
|
||||
|
|
Loading…
Reference in New Issue