Complementary Benefits of Contrastive Learning and Self-Training Under Distribution Shift