diff --git a/src/tserver/tablet_server-test.cc b/src/tserver/tablet_server-test.cc index 9771179..0dc0f3e 100644 --- a/src/tserver/tablet_server-test.cc +++ b/src/tserver/tablet_server-test.cc @@ -971,6 +971,60 @@ TEST_F(TabletServerTest, TestAlterSchema) { (KeyValue(3, 5))); } +// Regression test for KUDU-181. +TEST_F(TabletServerTest, TestAlterSchema_AddColWithoutWriteDefault) { + AlterSchemaRequestPB req; + AlterSchemaResponsePB resp; + RpcController rpc; + + InsertTestRowsRemote(0, 0, 2); + + // Add one column with a default value, and one column with no default. + const uint32_t c2_read_default = 7; + SchemaBuilder builder(schema_); + ASSERT_STATUS_OK(builder.AddColumn("c2", + UINT32, false, &c2_read_default, NULL)); + Schema s2 = builder.Build(); + + req.set_tablet_id(kTabletId); + req.set_schema_version(1); + ASSERT_STATUS_OK(SchemaToPB(s2, req.mutable_schema())); + + // Send the call + { + SCOPED_TRACE(req.DebugString()); + ASSERT_STATUS_OK(proxy_->AlterSchema(req, &resp, &rpc)); + SCOPED_TRACE(resp.DebugString()); + ASSERT_FALSE(resp.has_error()); + } + + // Verify that the old data picked up the read default. + + const Schema projection(boost::assign::list_of + (ColumnSchema("key", UINT32)) + (ColumnSchema("c2", UINT32)), + 1); + VerifyRows(projection, boost::assign::list_of(KeyValue(0, 7))); + + // Try recovering from the original log + ASSERT_NO_FATAL_FAILURE(ShutdownAndRebuildTablet()); + VerifyRows(projection, boost::assign::list_of(KeyValue(0, 7)) + (KeyValue(1, 7)) + (KeyValue(2, 5)) + (KeyValue(3, 5))); + VerifyRows(projection, boost::assign::list_of(KeyValue(0, 7))); + + // Try recovering from the log generated on recovery + ASSERT_NO_FATAL_FAILURE(ShutdownAndRebuildTablet()); + VerifyRows(projection, boost::assign::list_of(KeyValue(0, 7)) + (KeyValue(1, 7)) + (KeyValue(2, 5)) + (KeyValue(3, 5))); + VerifyRows(projection, boost::assign::list_of(KeyValue(0, 7))); +} + + + // TODO add a test for a quorum create tablet when the dist stuff is in TEST_F(TabletServerTest, TestCreateTablet_NoQuorum) { CreateTabletRequestPB req;