1) Generally, once someone has been exposed to a virus, their immune system develops antibodies geared towards fighting that particular strain of virus. Sometimes those antibodies can last a lifetime other times they only last months or (most often) many years. Regardless, once you've been sick with a particular virus you are immune to the virus for some time. Which is why you won;t get the flu twice in one season (exception being if there are two strains of flu going around in one season).
2) The flu changes every year. It evolves. That's why your immunity to last year's flu won't help you. The yearly flu shot is the best guess of scientists as to what the new flu will be like. Which is why the shot is not even close to 100% effective. Some years it's 35% effective, some years 75%. Because it's only a guess as to the composition of that year's flu strain.
3) No one knows if SARS-Coronovirus-2 will evolve yearly. Current best guesses are that it does not. So once infected and recovered, you will not be susceptible to it again for a long time. Once enough people have developed immunity, either naturally by being infected and recovering or by taking a vaccine (which does not yet exist), we have "herd immunity", which is when enough people are immune that on average, every sick person infects less than one other person. (The average number of people infected by every sick person is know as the R0. If the R0 is less than one, the virus dies out on its own because each person infects less than once other person on average).
4) As to knowing if you had the virus and are immune: the test being done in China would tell you that. The testing being done here in the US does not. Here in the Us we are using a PCR test. A PCR test (put very simply) is the nasal or throat swab, which is then examined for DNA of the virus. If you recovered they will not find any DNA from the virus and will not know if you had it and are immune or if you never had it. In Chine, however, they are doing an antibody test, which is a blood test. This looks for the presence of antibodies to SARS-CoV 2 which will indicate if the patient was exposed to the virus and developed antibodies, so this would show up even a year later. It's much more invasive and uncomfortable than the "drive by" swab testing, which is probably why it's not being done here.