ipfs-cluster/test/test_test.go
Hector Sanjuan 2512ecb701 Issue #41: Add Replication factor
New PeerManager, Allocator, Informer components have been added along
with a new "replication_factor" configuration option.

First, cluster peers collect and push metrics (Informer) to the Cluster
leader regularly. The Informer is an interface that can be implemented
in custom wayts to support custom metrics.

Second, on a pin operation, using the information from the collected metrics,
an Allocator can provide a list of preferences as to where the new pin
should be assigned. The Allocator is an interface allowing to provide
different allocation strategies.

Both Allocator and Informer are Cluster Componenets, and have access
to the RPC API.

The allocations are kept in the shared state. Cluster peer failure
detection is still missing and re-allocation is still missing, although
re-pinning something when a node is down/metrics missing does re-allocate
the pin somewhere else.

License: MIT
Signed-off-by: Hector Sanjuan <hector@protocol.ai>
2017-02-14 19:13:08 +01:00

63 lines
1.4 KiB
Go

package test
import (
"reflect"
"testing"
ipfscluster "github.com/ipfs/ipfs-cluster"
)
func TestIpfsMock(t *testing.T) {
ipfsmock := NewIpfsMock()
defer ipfsmock.Close()
}
// Test that our RPC mock resembles the original
func TestRPCMockValid(t *testing.T) {
mock := &mockService{}
real := &ipfscluster.RPCAPI{}
mockT := reflect.TypeOf(mock)
realT := reflect.TypeOf(real)
// Make sure all the methods we have match the original
for i := 0; i < mockT.NumMethod(); i++ {
method := mockT.Method(i)
name := method.Name
origMethod, ok := realT.MethodByName(name)
if !ok {
t.Fatalf("%s method not found in real RPC", name)
}
mType := method.Type
oType := origMethod.Type
if nout := mType.NumOut(); nout != 1 || nout != oType.NumOut() {
t.Errorf("%s: more than 1 out parameter", name)
}
if mType.Out(0).Name() != "error" {
t.Errorf("%s out param should be an error", name)
}
if nin := mType.NumIn(); nin != oType.NumIn() || nin != 3 {
t.Errorf("%s: num in parameter mismatch: %d vs. %d", name, nin, oType.NumIn())
}
for j := 1; j < 3; j++ {
mn := mType.In(j).String()
on := oType.In(j).String()
if mn != on {
t.Errorf("%s: name mismatch: %s vs %s", name, mn, on)
}
}
}
for i := 0; i < realT.NumMethod(); i++ {
name := realT.Method(i).Name
_, ok := mockT.MethodByName(name)
if !ok {
t.Logf("Warning: %s: unimplemented in mock rpc", name)
}
}
}