// NewDPNQueue creates a new DPNQueue object. Param _context is a Context // object, and param hours tells the code to examine all Replication, // Restore and DPN Ingest requests from the past N hours. func NewDPNQueue(_context *context.Context, hours int) (*DPNQueue, error) { if _context == nil { return nil, fmt.Errorf("Param _context cannot be nil.") } localClient, err := network.NewDPNRestClient( _context.Config.DPN.RestClient.LocalServiceURL, _context.Config.DPN.DPNAPIVersion, _context.Config.DPN.RestClient.LocalAuthToken, _context.Config.DPN.LocalNode, _context.Config.DPN) if err != nil { return nil, fmt.Errorf("Error creating local DPN REST client: %v", err) } remoteClients, err := localClient.GetRemoteClients() if err != nil { return nil, fmt.Errorf("Error creating remote DPN REST client: %v", err) } sinceWhen := time.Now().UTC().Add(time.Duration(-1*hours) * time.Hour) _context.MessageLog.Info("Checking records since %d hours ago (%s)", hours, sinceWhen.Format(time.RFC3339)) dpnQueue := DPNQueue{ LocalClient: localClient, RemoteNodes: make(map[string]*models.Node), RemoteClients: remoteClients, Context: _context, ExamineItemsSince: sinceWhen, QueueResult: models.NewQueueResult(), } return &dpnQueue, nil }
func TestAddAndHasErrors(t *testing.T) { result := models.NewQueueResult() require.NotNil(t, result) assert.Empty(t, result.Errors) assert.False(t, result.HasErrors()) result.AddError("Oops!") assert.True(t, result.HasErrors()) }
func TestNewQueueResult(t *testing.T) { result := models.NewQueueResult() require.NotNil(t, result) assert.NotNil(t, result.Replications) assert.NotNil(t, result.Restores) assert.NotNil(t, result.Ingests) assert.NotNil(t, result.Errors) }
func TestAddAndFindIngest(t *testing.T) { result := models.NewQueueResult() require.NotNil(t, result) assert.Empty(t, result.Ingests) result.AddIngest(models.NewQueueItem("ingest1")) assert.Equal(t, 1, len(result.Ingests)) item := result.FindIngest("ingest1") require.NotNil(t, item) assert.Equal(t, "ingest1", item.Identifier) assert.Nil(t, result.FindIngest("does not exist")) }
func TestAddAndFindReplication(t *testing.T) { result := models.NewQueueResult() require.NotNil(t, result) assert.Empty(t, result.Replications) result.AddReplication(models.NewQueueItem("replication1")) assert.Equal(t, 1, len(result.Replications)) item := result.FindReplication("replication1") require.NotNil(t, item) assert.Equal(t, "replication1", item.Identifier) assert.Nil(t, result.FindReplication("does not exist")) }