Commit 984dd224 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer/rpc: Cache

parent e9f7a141
......@@ -2,7 +2,6 @@ package rpc
import (
"github.com/mitchellh/packer/packer"
"net/rpc"
"testing"
)
......@@ -52,19 +51,14 @@ func TestCacheRPC(t *testing.T) {
c := new(testCache)
// Start the server
server := rpc.NewServer()
RegisterCache(server, c)
address := serveSingleConn(server)
// Create the client over RPC and run some methods to verify it works
rpcClient, err := rpc.Dial("tcp", address)
if err != nil {
t.Fatalf("bad: %s", err)
}
client := Cache(rpcClient)
server := NewServer()
server.RegisterCache(c)
client := testClient(t, server)
defer client.Close()
cacheClient := client.Cache()
// Test Lock
client.Lock("foo")
cacheClient.Lock("foo")
if !c.lockCalled {
t.Fatal("should be called")
}
......@@ -73,7 +67,7 @@ func TestCacheRPC(t *testing.T) {
}
// Test Unlock
client.Unlock("foo")
cacheClient.Unlock("foo")
if !c.unlockCalled {
t.Fatal("should be called")
}
......@@ -82,7 +76,7 @@ func TestCacheRPC(t *testing.T) {
}
// Test RLock
client.RLock("foo")
cacheClient.RLock("foo")
if !c.rlockCalled {
t.Fatal("should be called")
}
......@@ -91,7 +85,7 @@ func TestCacheRPC(t *testing.T) {
}
// Test RUnlock
client.RUnlock("foo")
cacheClient.RUnlock("foo")
if !c.runlockCalled {
t.Fatal("should be called")
}
......
......@@ -31,8 +31,22 @@ func NewClient(rwc io.ReadWriteCloser) (*Client, error) {
}, nil
}
func (c *Client) Close() error {
if err := c.client.Close(); err != nil {
return err
}
return c.mux.Close()
}
func (c *Client) Artifact() packer.Artifact {
return &artifact{
client: c.client,
}
}
func (c *Client) Cache() packer.Cache {
return &cache{
client: c.client,
}
}
......@@ -28,6 +28,10 @@ func (s *Server) RegisterArtifact(a packer.Artifact) {
s.registerComponent("Artifact", &ArtifactServer{a}, false)
}
func (s *Server) RegisterCache(c packer.Cache) {
s.registerComponent("Cache", &CacheServer{c}, false)
}
// ServeConn serves a single connection over the RPC server. It is up
// to the caller to obtain a proper io.ReadWriteCloser.
func (s *Server) ServeConn(conn io.ReadWriteCloser) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment