github.com/smugmug/godynamo@v0.0.0-20151122084750-7913028f6623/tests/update_table-livetest.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/smugmug/godynamo/conf"
     6  	"github.com/smugmug/godynamo/conf_file"
     7  	conf_iam "github.com/smugmug/godynamo/conf_iam"
     8  	desc "github.com/smugmug/godynamo/endpoints/describe_table"
     9  	list "github.com/smugmug/godynamo/endpoints/list_tables"
    10  	update_table "github.com/smugmug/godynamo/endpoints/update_table"
    11  	keepalive "github.com/smugmug/godynamo/keepalive"
    12  	"log"
    13  	"net/http"
    14  	"os"
    15  )
    16  
    17  func main() {
    18  	conf_file.Read()
    19  	conf.Vals.ConfLock.RLock()
    20  	if conf.Vals.Initialized == false {
    21  		panic("the conf.Vals global conf struct has not been initialized")
    22  	}
    23  
    24  	// launch a background poller to keep conns to aws alive
    25  	if conf.Vals.Network.DynamoDB.KeepAlive {
    26  		log.Printf("launching background keepalive")
    27  		go keepalive.KeepAlive([]string{})
    28  	}
    29  
    30  	// deal with iam, or not
    31  	if conf.Vals.UseIAM {
    32  		iam_ready_chan := make(chan bool)
    33  		go conf_iam.GoIAM(iam_ready_chan)
    34  		_ = <-iam_ready_chan
    35  	}
    36  	conf.Vals.ConfLock.RUnlock()
    37  
    38  	tn := "test-godynamo-livetest"
    39  	tablename1 := tn
    40  	fmt.Printf("tablename1: %s\n", tablename1)
    41  
    42  	var code int
    43  	var err error
    44  	var body []byte
    45  
    46  	update_table1 := update_table.NewUpdateTable()
    47  	update_table1.TableName = tablename1
    48  	update_table1.ProvisionedThroughput.ReadCapacityUnits = 200
    49  	update_table1.ProvisionedThroughput.WriteCapacityUnits = 200
    50  	body, code, err = update_table1.EndpointReq()
    51  	if err != nil || code != http.StatusOK {
    52  		fmt.Printf("update table failed %d %v %s\n", code, err, string(body))
    53  		os.Exit(1)
    54  	}
    55  
    56  	// WAIT FOR THE PROVISIONING TO FINISH
    57  	fmt.Printf("checking for ACTIVE status for update....\n")
    58  	active, poll_err := desc.PollTableStatus(tablename1,
    59  		desc.ACTIVE, 100)
    60  	if poll_err != nil {
    61  		fmt.Printf("poll1:%v\n", poll_err)
    62  		os.Exit(1)
    63  	}
    64  	fmt.Printf("ACTIVE:%v\n", active)
    65  
    66  	var desc1 desc.DescribeTable
    67  	desc1.TableName = tablename1
    68  	body, code, err = desc1.EndpointReq()
    69  	if err != nil || code != http.StatusOK {
    70  		fmt.Printf("desc failed %d %v %s\n", code, err, string(body))
    71  		os.Exit(1)
    72  	}
    73  	fmt.Printf("desc:%v\n%v\n,%v\n", string(body), code, err)
    74  
    75  	// WAIT FOR IT TO BE ACTIVE
    76  	fmt.Printf("checking for ACTIVE status for table....\n")
    77  	active, poll_err = desc.PollTableStatus(tablename1, desc.ACTIVE, 100)
    78  	if poll_err != nil {
    79  		fmt.Printf("poll1:%v\n", poll_err)
    80  		os.Exit(1)
    81  	}
    82  	fmt.Printf("ACTIVE:%v\n", active)
    83  
    84  	// List TABLES
    85  	var l list.List
    86  	l.ExclusiveStartTableName = ""
    87  	l.Limit = 100
    88  	body, code, err = l.EndpointReq()
    89  	if err != nil || code != http.StatusOK {
    90  		fmt.Printf("list failed %d %v %s\n", code, err, string(body))
    91  		os.Exit(1)
    92  	}
    93  	fmt.Printf("%v\n%v\n,%v\n", string(body), code, err)
    94  
    95  }