Example #1
0
func TestDispatcher(t *testing.T) {

	var registryProxy *registry.RegistryProxy
	var dispatcherHost string
	var dispatcherProxy *DispatcherProxy
	var err error

	// start up the registry
	{
		host := piazza.GetRandomHost()
		go registry.NewRegistryService(host, "my registry")
		time.Sleep(1 * time.Second)

		registryProxy, err = registry.NewRegistryProxy(host)
		if err != nil {
			t.Error(err)
		}
	}

	// start the dispatcher
	{
		dispatcherHost = piazza.GetRandomHost()
		go NewDispatcherService(dispatcherHost, registryProxy)
		time.Sleep(1 * time.Second)
	}

	// start the dispatcher proxy
	{
		dispatcherProxy, err = NewDispatcherProxy(dispatcherHost)
		if err != nil {
			t.Error(err)
		}
		log.Printf("%v", dispatcherProxy)
	}
}
Example #2
0
func setup(t *testing.T) *GatewayProxy {
	var err error

	var registryHost = piazza.GetRandomHost()
	var registryProxy *registry.RegistryProxy

	var dispatcherHost = piazza.GetRandomHost()
	var dispatcherProxy *dispatcher.DispatcherProxy

	var gatewayHost = piazza.GetRandomHost()
	var gatewayProxy *GatewayProxy

	{
		go registry.NewRegistryService(registryHost, "my registry")
		time.Sleep(250 * time.Millisecond)

		registryProxy, err = registry.NewRegistryProxy(registryHost)
		if err != nil {
			t.Error(err)
		}
	}
	{
		go dispatcher.NewDispatcherService(dispatcherHost, registryProxy)
		time.Sleep(250 * time.Millisecond)

		dispatcherProxy, err = dispatcher.NewDispatcherProxy(dispatcherHost)
		if err != nil {
			t.Error(err)
		}
	}
	{
		go NewGatewayService(gatewayHost, registryProxy)
		time.Sleep(250 * time.Millisecond)

		gatewayProxy, err = NewGatewayProxy(gatewayHost, dispatcherProxy)
		if err != nil {
			t.Error(err)
		}
	}

	return gatewayProxy
}
Example #3
0
func TestRegistry(t *testing.T) {
	var host string
	var proxy *RegistryProxy
	var err error

	// create it, start the proxy
	{
		host = piazza.GetRandomHost()
		go NewRegistryService(host, "my registry")
		time.Sleep(1 * time.Second)

		proxy, err = NewRegistryProxy(host)
		if err != nil {
			t.Error(err)
		}
	}

	// verify only entry is itself
	{
		list, err := proxy.Lookup(piazza.InvalidService)
		if err != nil {
			t.Error(err)
		}

		if list.Len() != 1 {
			t.Errorf("list length %d, expected 1", list.Len())
		}

		service, ok := list.GetOne()
		if !ok {
			t.Error("serivce list is not length 1")
		}
		if service.Type != piazza.RegistryService {
			t.Error("single service is not a RegistryService")
		}
		if service.Id == "" {
			t.Errorf("service id is invalid: %s", service.Id)
		}
		//t.Log(service)
	}

	// add a service
	{
		pid, err := proxy.Register(host, piazza.DispatcherService, "This is my service.")
		if err != nil {
			t.Error(err)
		}
		t.Logf("pid: %v", pid)
	}

	// check what we added
	var addedId piazza.PiazzaId
	{
		list, err := proxy.Lookup(piazza.DispatcherService)
		if err != nil {
			t.Error(err)
		}

		if list.Len() != 1 {
			t.Errorf("list length %d, expected 1", list.Len())
		}

		service, ok := list.GetOne()
		if !ok {
			t.Error("serivce list is not length 1")
		}
		if service.Type != piazza.DispatcherService {
			t.Error("service is not a DispatcherService")
		}
		if service.Comment != "This is my service." {
			t.Error("service comment is \"%s\", expected \"%s\"", service.Comment, "This is my service.")
		}
		addedId = service.Id
	}

	// remove the service
	{
		err := proxy.Remove(addedId)
		if err != nil {
			t.Error(err)
		}
	}

	// verify the table is empty
	{
		/** TODO
		list, err := proxy.Lookup(piazza.InvalidService)
		if err != nil {
			t.Error(err)
		}

		if list.Len() != 0 {
			t.Errorf("list length %d, expected 0", list.Len())
		}
		**/
	}
}