@@ -38,89 +38,53 @@ public class RowMutationTest {
3838 private static final String APP_PROFILE_ID = "fake-profile" ;
3939 private static final RequestContext REQUEST_CONTEXT =
4040 RequestContext .create (INSTANCE_NAME , APP_PROFILE_ID );
41+ private static final String TABLE_ID = "fake-table" ;
42+ private static final ByteString ROW_KEY = ByteString .copyFromUtf8 ("fake-key" );
43+ private static final String FAMILY_NAME = "fake-family" ;
44+ private static final ByteString QUALIFIER = ByteString .copyFromUtf8 ("fake-qualifier" );
45+ private static final ByteString VALUE = ByteString .copyFromUtf8 ("fake-value" );
46+ private static final String TABLE_NAME = TableName
47+ .of (INSTANCE_NAME .getProject (), INSTANCE_NAME .getInstance (), "fake-table" )
48+ .toString ();
49+ private static final long TIMESTAMP = System .currentTimeMillis () * 1_000 ;
4150
4251 @ Test
4352 public void toProtoTest () {
44- long timestampMin = System .currentTimeMillis () * 1_000 ;
45-
4653 RowMutation rowMutation =
47- RowMutation .create ("fake-table" , "fake-key" )
48- .setCell ("fake-family" , "fake-qualifier" , "fake-value" );
54+ RowMutation .create (TABLE_ID , ROW_KEY )
55+ .setCell (FAMILY_NAME , QUALIFIER , TIMESTAMP , VALUE );
4956
5057 MutateRowRequest actualRowMutation = rowMutation .toProto (REQUEST_CONTEXT );
51- com .google .common .collect .Range <Long > timestampRange =
52- com .google .common .collect .Range .closed (timestampMin , System .currentTimeMillis () * 1_000 );
53-
54- assertThat (actualRowMutation .getTableName ())
55- .isEqualTo (
56- TableName .of (INSTANCE_NAME .getProject (), INSTANCE_NAME .getInstance (), "fake-table" )
57- .toString ());
58- assertThat (actualRowMutation .getAppProfileId ()).isEqualTo (APP_PROFILE_ID );
59- assertThat (actualRowMutation .getMutationsList ()).hasSize (1 );
60- assertThat (actualRowMutation .getMutations (0 ).getSetCell ().getValue ())
61- .isEqualTo (ByteString .copyFromUtf8 ("fake-value" ));
62- assertThat (actualRowMutation .getMutations (0 ).getSetCell ().getTimestampMicros ())
63- .isIn (timestampRange );
58+
59+ assertThat (actualRowMutation ).isEqualTo (createMutateRowRequest ());
6460 }
6561
6662 @ Test
6763 public void toBulkProtoTest () {
68- long timestampMin = System .currentTimeMillis () * 1_000 ;
69-
7064 RowMutation rowMutation =
71- RowMutation .create ("fake-table" , "fake-key" )
72- .setCell ("fake-family" , "fake-qualifier" , "fake-value" );
65+ RowMutation .create (TABLE_ID , ROW_KEY )
66+ .setCell (FAMILY_NAME , QUALIFIER , TIMESTAMP , VALUE );
7367
7468 MutateRowsRequest actualRowMutation = rowMutation .toBulkProto (REQUEST_CONTEXT );
7569
76- com .google .common .collect .Range <Long > timestampRange =
77- com .google .common .collect .Range .closed (timestampMin , System .currentTimeMillis () * 1_000 );
78-
79- assertThat (actualRowMutation .getTableName ())
80- .isEqualTo (
81- TableName .of (INSTANCE_NAME .getProject (), INSTANCE_NAME .getInstance (), "fake-table" )
82- .toString ());
83- assertThat (actualRowMutation .getAppProfileId ()).isEqualTo (APP_PROFILE_ID );
84- assertThat (actualRowMutation .getEntriesList ()).hasSize (1 );
85- assertThat (actualRowMutation .getEntries (0 ).getMutationsList ()).hasSize (1 );
86- assertThat (actualRowMutation .getEntries (0 ).getMutations (0 ).getSetCell ().getValue ())
87- .isEqualTo (ByteString .copyFromUtf8 ("fake-value" ));
88-
89- assertThat (actualRowMutation .getEntries (0 ).getMutations (0 ).getSetCell ().getTimestampMicros ())
90- .isIn (timestampRange );
70+ assertThat (actualRowMutation ).isEqualTo (createMutateRowsRequest ());
9171 }
9272
9373 @ Test
9474 public void toProtoTestWithProvidedMutation () {
95- long timestampMin = System .currentTimeMillis () * 1_000 ;
96-
97- Mutation mutation = Mutation .create ().setCell ("fake-family" , "fake-qualifier" , "fake-value" );
98- RowMutation rowMutation = RowMutation .create ("fake-table" , "fake-key" , mutation );
75+ Mutation mutation = Mutation .create ().setCell (FAMILY_NAME , QUALIFIER , TIMESTAMP , VALUE );
76+ RowMutation rowMutation = RowMutation .create (TABLE_ID , ROW_KEY , mutation );
9977
100- MutateRowsRequest actualRowMutation = rowMutation .toBulkProto (REQUEST_CONTEXT );
78+ MutateRowRequest actualRowMutation = rowMutation .toProto (REQUEST_CONTEXT );
10179
102- com .google .common .collect .Range <Long > timestampRange =
103- com .google .common .collect .Range .closed (timestampMin , System .currentTimeMillis () * 1_000 );
104-
105- assertThat (actualRowMutation .getTableName ())
106- .isEqualTo (
107- TableName .of (INSTANCE_NAME .getProject (), INSTANCE_NAME .getInstance (), "fake-table" )
108- .toString ());
109- assertThat (actualRowMutation .getAppProfileId ()).isEqualTo (APP_PROFILE_ID );
110- assertThat (actualRowMutation .getEntriesList ()).hasSize (1 );
111- assertThat (actualRowMutation .getEntries (0 ).getMutationsList ()).hasSize (1 );
112- assertThat (actualRowMutation .getEntries (0 ).getMutations (0 ).getSetCell ().getValue ())
113- .isEqualTo (ByteString .copyFromUtf8 ("fake-value" ));
114-
115- assertThat (actualRowMutation .getEntries (0 ).getMutations (0 ).getSetCell ().getTimestampMicros ())
116- .isIn (timestampRange );
80+ assertThat (actualRowMutation ).isEqualTo (createMutateRowRequest ());
11781 }
11882
11983 @ Test
12084 public void serializationTest () throws IOException , ClassNotFoundException {
12185 RowMutation expected =
122- RowMutation .create ("fake-table" , "fake-key" )
123- .setCell ("fake-family" , "fake-qualifier" , 10_000 , "fake-value" );
86+ RowMutation .create (TABLE_ID , ROW_KEY )
87+ .setCell (FAMILY_NAME , QUALIFIER , TIMESTAMP , VALUE );
12488
12589 ByteArrayOutputStream bos = new ByteArrayOutputStream ();
12690 ObjectOutputStream oos = new ObjectOutputStream (bos );
@@ -132,4 +96,43 @@ public void serializationTest() throws IOException, ClassNotFoundException {
13296 RowMutation actual = (RowMutation ) ois .readObject ();
13397 assertThat (actual .toProto (REQUEST_CONTEXT )).isEqualTo (expected .toProto (REQUEST_CONTEXT ));
13498 }
99+
100+ private static com .google .bigtable .v2 .Mutation .SetCell createSetCell () {
101+ return com .google .bigtable .v2 .Mutation .SetCell .newBuilder ()
102+ .setFamilyName (FAMILY_NAME )
103+ .setColumnQualifier (QUALIFIER )
104+ .setValue (VALUE )
105+ .setTimestampMicros (TIMESTAMP )
106+ .build ();
107+ }
108+
109+ private static com .google .bigtable .v2 .Mutation createSetCellMutation () {
110+ return com .google .bigtable .v2 .Mutation .newBuilder ()
111+ .setSetCell (createSetCell ())
112+ .build ();
113+ }
114+
115+ private static MutateRowRequest createMutateRowRequest () {
116+ return MutateRowRequest .newBuilder ()
117+ .addMutations (createSetCellMutation ())
118+ .setAppProfileId (APP_PROFILE_ID )
119+ .setTableName (TABLE_NAME )
120+ .setRowKey (ROW_KEY )
121+ .build ();
122+ }
123+
124+ private static MutateRowsRequest .Entry createEntry () {
125+ return MutateRowsRequest .Entry .newBuilder ()
126+ .addMutations (createSetCellMutation ())
127+ .setRowKey (ROW_KEY )
128+ .build ();
129+ }
130+
131+ private static MutateRowsRequest createMutateRowsRequest () {
132+ return MutateRowsRequest .newBuilder ()
133+ .addEntries (createEntry ())
134+ .setAppProfileId (APP_PROFILE_ID )
135+ .setTableName (TABLE_NAME )
136+ .build ();
137+ }
135138}
0 commit comments