|
11 | 11 | NodeMigratedNotification, |
12 | 12 | NodeFailingOverNotification, |
13 | 13 | NodeFailedOverNotification, |
| 14 | + OSSNodeMigratingNotification, |
| 15 | + OSSNodeMigratedNotification, |
14 | 16 | MaintNotificationsConfig, |
15 | 17 | MaintNotificationsPoolHandler, |
16 | 18 | MaintNotificationsConnectionHandler, |
@@ -381,6 +383,238 @@ def test_equality_and_hash(self): |
381 | 383 | assert hash(notification1) != hash(notification3) |
382 | 384 |
|
383 | 385 |
|
| 386 | +class TestOSSNodeMigratingNotification: |
| 387 | + """Test the OSSNodeMigratingNotification class.""" |
| 388 | + |
| 389 | + def test_init_with_defaults(self): |
| 390 | + """Test OSSNodeMigratingNotification initialization with default values.""" |
| 391 | + with patch("time.monotonic", return_value=1000): |
| 392 | + notification = OSSNodeMigratingNotification(id=1) |
| 393 | + assert notification.id == 1 |
| 394 | + assert notification.ttl == OSSNodeMigratingNotification.DEFAULT_TTL |
| 395 | + assert notification.creation_time == 1000 |
| 396 | + assert notification.src_node is None |
| 397 | + assert notification.dest_node is None |
| 398 | + assert notification.slots is None |
| 399 | + |
| 400 | + def test_init_with_all_parameters(self): |
| 401 | + """Test OSSNodeMigratingNotification initialization with all parameters.""" |
| 402 | + with patch("time.monotonic", return_value=1000): |
| 403 | + slots = [1, 2, 3, 4, 5] |
| 404 | + notification = OSSNodeMigratingNotification( |
| 405 | + id=1, |
| 406 | + src_node="127.0.0.1:6379", |
| 407 | + dest_node="127.0.0.1:6380", |
| 408 | + slots=slots, |
| 409 | + ) |
| 410 | + assert notification.id == 1 |
| 411 | + assert notification.ttl == OSSNodeMigratingNotification.DEFAULT_TTL |
| 412 | + assert notification.creation_time == 1000 |
| 413 | + assert notification.src_node == "127.0.0.1:6379" |
| 414 | + assert notification.dest_node == "127.0.0.1:6380" |
| 415 | + assert notification.slots == slots |
| 416 | + |
| 417 | + def test_default_ttl(self): |
| 418 | + """Test that DEFAULT_TTL is used correctly.""" |
| 419 | + assert OSSNodeMigratingNotification.DEFAULT_TTL == 30 |
| 420 | + notification = OSSNodeMigratingNotification(id=1) |
| 421 | + assert notification.ttl == 30 |
| 422 | + |
| 423 | + def test_repr(self): |
| 424 | + """Test OSSNodeMigratingNotification string representation.""" |
| 425 | + with patch("time.monotonic", return_value=1000): |
| 426 | + notification = OSSNodeMigratingNotification( |
| 427 | + id=1, |
| 428 | + src_node="127.0.0.1:6379", |
| 429 | + dest_node="127.0.0.1:6380", |
| 430 | + slots=[1, 2, 3], |
| 431 | + ) |
| 432 | + |
| 433 | + with patch("time.monotonic", return_value=1005): # 5 seconds later |
| 434 | + repr_str = repr(notification) |
| 435 | + assert "OSSNodeMigratingNotification" in repr_str |
| 436 | + assert "id=1" in repr_str |
| 437 | + assert "ttl=30" in repr_str |
| 438 | + assert "remaining=25.0s" in repr_str |
| 439 | + assert "expired=False" in repr_str |
| 440 | + |
| 441 | + def test_equality_same_id_and_type(self): |
| 442 | + """Test equality for notifications with same id and type.""" |
| 443 | + notification1 = OSSNodeMigratingNotification( |
| 444 | + id=1, |
| 445 | + src_node="127.0.0.1:6379", |
| 446 | + dest_node="127.0.0.1:6380", |
| 447 | + slots=[1, 2, 3], |
| 448 | + ) |
| 449 | + notification2 = OSSNodeMigratingNotification( |
| 450 | + id=1, |
| 451 | + src_node="127.0.0.1:6381", |
| 452 | + dest_node="127.0.0.1:6382", |
| 453 | + slots=[4, 5, 6], |
| 454 | + ) |
| 455 | + # Should be equal because id and type are the same |
| 456 | + assert notification1 == notification2 |
| 457 | + |
| 458 | + def test_equality_different_id(self): |
| 459 | + """Test inequality for notifications with different id.""" |
| 460 | + notification1 = OSSNodeMigratingNotification(id=1) |
| 461 | + notification2 = OSSNodeMigratingNotification(id=2) |
| 462 | + assert notification1 != notification2 |
| 463 | + |
| 464 | + def test_equality_different_type(self): |
| 465 | + """Test inequality for notifications of different types.""" |
| 466 | + notification1 = OSSNodeMigratingNotification(id=1) |
| 467 | + notification2 = NodeMigratingNotification(id=1, ttl=30) |
| 468 | + assert notification1 != notification2 |
| 469 | + |
| 470 | + def test_hash_same_id_and_type(self): |
| 471 | + """Test hash for notifications with same id and type.""" |
| 472 | + notification1 = OSSNodeMigratingNotification( |
| 473 | + id=1, |
| 474 | + src_node="127.0.0.1:6379", |
| 475 | + dest_node="127.0.0.1:6380", |
| 476 | + slots=[1, 2, 3], |
| 477 | + ) |
| 478 | + notification2 = OSSNodeMigratingNotification( |
| 479 | + id=1, |
| 480 | + src_node="127.0.0.1:6381", |
| 481 | + dest_node="127.0.0.1:6382", |
| 482 | + slots=[4, 5, 6], |
| 483 | + ) |
| 484 | + # Should have same hash because id and type are the same |
| 485 | + assert hash(notification1) == hash(notification2) |
| 486 | + |
| 487 | + def test_hash_different_id(self): |
| 488 | + """Test hash for notifications with different id.""" |
| 489 | + notification1 = OSSNodeMigratingNotification(id=1) |
| 490 | + notification2 = OSSNodeMigratingNotification(id=2) |
| 491 | + assert hash(notification1) != hash(notification2) |
| 492 | + |
| 493 | + def test_in_set(self): |
| 494 | + """Test that notifications can be used in sets.""" |
| 495 | + notification1 = OSSNodeMigratingNotification(id=1) |
| 496 | + notification2 = OSSNodeMigratingNotification(id=1) |
| 497 | + notification3 = OSSNodeMigratingNotification(id=2) |
| 498 | + notification4 = OSSNodeMigratingNotification(id=2) |
| 499 | + |
| 500 | + notification_set = {notification1, notification2, notification3, notification4} |
| 501 | + assert ( |
| 502 | + len(notification_set) == 2 |
| 503 | + ) # notification1 and notification2 should be the same |
| 504 | + |
| 505 | + |
| 506 | +class TestOSSNodeMigratedNotification: |
| 507 | + """Test the OSSNodeMigratedNotification class.""" |
| 508 | + |
| 509 | + def test_init_with_defaults(self): |
| 510 | + """Test OSSNodeMigratedNotification initialization with default values.""" |
| 511 | + with patch("time.monotonic", return_value=1000): |
| 512 | + notification = OSSNodeMigratedNotification(id=1) |
| 513 | + assert notification.id == 1 |
| 514 | + assert notification.ttl == OSSNodeMigratedNotification.DEFAULT_TTL |
| 515 | + assert notification.creation_time == 1000 |
| 516 | + assert notification.node_address is None |
| 517 | + assert notification.slots is None |
| 518 | + |
| 519 | + def test_init_with_all_parameters(self): |
| 520 | + """Test OSSNodeMigratedNotification initialization with all parameters.""" |
| 521 | + with patch("time.monotonic", return_value=1000): |
| 522 | + slots = [1, 2, 3, 4, 5] |
| 523 | + notification = OSSNodeMigratedNotification( |
| 524 | + id=1, |
| 525 | + node_address="127.0.0.1:6380", |
| 526 | + slots=slots, |
| 527 | + ) |
| 528 | + assert notification.id == 1 |
| 529 | + assert notification.ttl == OSSNodeMigratedNotification.DEFAULT_TTL |
| 530 | + assert notification.creation_time == 1000 |
| 531 | + assert notification.node_address == "127.0.0.1:6380" |
| 532 | + assert notification.slots == slots |
| 533 | + |
| 534 | + def test_default_ttl(self): |
| 535 | + """Test that DEFAULT_TTL is used correctly.""" |
| 536 | + assert OSSNodeMigratedNotification.DEFAULT_TTL == 30 |
| 537 | + notification = OSSNodeMigratedNotification(id=1) |
| 538 | + assert notification.ttl == 30 |
| 539 | + |
| 540 | + def test_repr(self): |
| 541 | + """Test OSSNodeMigratedNotification string representation.""" |
| 542 | + with patch("time.monotonic", return_value=1000): |
| 543 | + notification = OSSNodeMigratedNotification( |
| 544 | + id=1, |
| 545 | + node_address="127.0.0.1:6380", |
| 546 | + slots=[1, 2, 3], |
| 547 | + ) |
| 548 | + |
| 549 | + with patch("time.monotonic", return_value=1010): # 10 seconds later |
| 550 | + repr_str = repr(notification) |
| 551 | + assert "OSSNodeMigratedNotification" in repr_str |
| 552 | + assert "id=1" in repr_str |
| 553 | + assert "ttl=30" in repr_str |
| 554 | + assert "remaining=20.0s" in repr_str |
| 555 | + assert "expired=False" in repr_str |
| 556 | + |
| 557 | + def test_equality_same_id_and_type(self): |
| 558 | + """Test equality for notifications with same id and type.""" |
| 559 | + notification1 = OSSNodeMigratedNotification( |
| 560 | + id=1, |
| 561 | + node_address="127.0.0.1:6380", |
| 562 | + slots=[1, 2, 3], |
| 563 | + ) |
| 564 | + notification2 = OSSNodeMigratedNotification( |
| 565 | + id=1, |
| 566 | + node_address="127.0.0.1:6381", |
| 567 | + slots=[4, 5, 6], |
| 568 | + ) |
| 569 | + # Should be equal because id and type are the same |
| 570 | + assert notification1 == notification2 |
| 571 | + |
| 572 | + def test_equality_different_id(self): |
| 573 | + """Test inequality for notifications with different id.""" |
| 574 | + notification1 = OSSNodeMigratedNotification(id=1) |
| 575 | + notification2 = OSSNodeMigratedNotification(id=2) |
| 576 | + assert notification1 != notification2 |
| 577 | + |
| 578 | + def test_equality_different_type(self): |
| 579 | + """Test inequality for notifications of different types.""" |
| 580 | + notification1 = OSSNodeMigratedNotification(id=1) |
| 581 | + notification2 = NodeMigratedNotification(id=1) |
| 582 | + assert notification1 != notification2 |
| 583 | + |
| 584 | + def test_hash_same_id_and_type(self): |
| 585 | + """Test hash for notifications with same id and type.""" |
| 586 | + notification1 = OSSNodeMigratedNotification( |
| 587 | + id=1, |
| 588 | + node_address="127.0.0.1:6380", |
| 589 | + slots=[1, 2, 3], |
| 590 | + ) |
| 591 | + notification2 = OSSNodeMigratedNotification( |
| 592 | + id=1, |
| 593 | + node_address="127.0.0.1:6381", |
| 594 | + slots=[4, 5, 6], |
| 595 | + ) |
| 596 | + # Should have same hash because id and type are the same |
| 597 | + assert hash(notification1) == hash(notification2) |
| 598 | + |
| 599 | + def test_hash_different_id(self): |
| 600 | + """Test hash for notifications with different id.""" |
| 601 | + notification1 = OSSNodeMigratedNotification(id=1) |
| 602 | + notification2 = OSSNodeMigratedNotification(id=2) |
| 603 | + assert hash(notification1) != hash(notification2) |
| 604 | + |
| 605 | + def test_in_set(self): |
| 606 | + """Test that notifications can be used in sets.""" |
| 607 | + notification1 = OSSNodeMigratedNotification(id=1) |
| 608 | + notification2 = OSSNodeMigratedNotification(id=1) |
| 609 | + notification3 = OSSNodeMigratedNotification(id=2) |
| 610 | + notification4 = OSSNodeMigratedNotification(id=2) |
| 611 | + |
| 612 | + notification_set = {notification1, notification2, notification3, notification4} |
| 613 | + assert ( |
| 614 | + len(notification_set) == 2 |
| 615 | + ) # notification1 and notification2 should be the same |
| 616 | + |
| 617 | + |
384 | 618 | class TestMaintNotificationsConfig: |
385 | 619 | """Test the MaintNotificationsConfig class.""" |
386 | 620 |
|
|
0 commit comments