1) Mary has worked as a teacher [for over 25 years].
2) It has rained heavily [for 2 hours].
First, some info on the present perfect:
The present perfect can locate the referred to time to be completely in the past (non-continuative reading), or it can begin in the past but continues forward to also include the present (continuative reading).
A non-continuative reading is the more frequent one, and it can be considered to be the default. (CGEL page 141)
To have a continuative reading, that usually requires the presence of a time adjunct, such as a "since" or "for" phrase. (Or else a duration adjunct is recoverable from the context.)
Many times the reading (continuative vs non-continuative) can be ambiguous (even when time adjuncts are used), and often it is the context that determines which reading is intended.
The situation described by the present perfect (directly or due to a resulting side-effect) has current relevance to the present time. This is why, in general, that time adjuncts that refer wholly only to the past are usually excluded--because they divorce the present time; though there are exceptions.
Your example #1 would seem to have a continuative reading, due to the presence of the time adjunct phrase "for over 25 years". That means that Mary is probably still working as a teacher right now.
Your example #2 also uses a time adjunct phrase ("for 2 hours"), and it also uses the present perfect instead of the past perfect (e.g. "It had rained heavily for 2 hours"), and so, the preferred, or expected, interpretation might be the continuative reading--though, the context will be important. That is, it is probably still raining.
Though, note that because your example #2 concerns the weather, it might be slightly different (from the way #1 was looked at). For instance, there could be an interpretation like the following in certain contexts: because it has rained for two hours it is now too wet outside to go camping even though the rain has stopped)--which involves a non-continuative reading. (imo)
You can explicitly disambiguate the intended reading (continuative vs non-continuative) by adding extra text. E.g. "Mary has worked as a teacher for over 25 years, and she is still teaching."
For some more related info, there's the 2002 reference grammar by Huddleston and Pullum et al., The Cambridge Grammar of the English Language (CGEL), pages 139-146. There is also the 2005 textbook by Huddleston and Pullum, A Student's Introduction to English Grammar, pages 48-51.