@@ -1377,3 +1377,211 @@ def test_call_schedule_service_update_before_create(
1377
1377
assert e .match (
1378
1378
regexp = r"Not updating PipelineJobSchedule: PipelineJobSchedule must be active or completed."
1379
1379
)
1380
+
1381
+ @pytest .mark .parametrize (
1382
+ "job_spec" ,
1383
+ [_TEST_PIPELINE_SPEC_JSON , _TEST_PIPELINE_SPEC_YAML , _TEST_PIPELINE_JOB ],
1384
+ )
1385
+ def test_get_max_run_count_before_create (
1386
+ self ,
1387
+ mock_schedule_service_create ,
1388
+ mock_schedule_service_get ,
1389
+ mock_schedule_bucket_exists ,
1390
+ job_spec ,
1391
+ mock_load_yaml_and_json ,
1392
+ ):
1393
+ """Gets the PipelineJobSchedule max_run_count before creating.
1394
+
1395
+ Raises error because PipelineJobSchedule should be created first.
1396
+ """
1397
+ aiplatform .init (
1398
+ project = _TEST_PROJECT ,
1399
+ staging_bucket = _TEST_GCS_BUCKET_NAME ,
1400
+ location = _TEST_LOCATION ,
1401
+ credentials = _TEST_CREDENTIALS ,
1402
+ )
1403
+
1404
+ job = pipeline_jobs .PipelineJob (
1405
+ display_name = _TEST_PIPELINE_JOB_DISPLAY_NAME ,
1406
+ template_path = _TEST_TEMPLATE_PATH ,
1407
+ parameter_values = _TEST_PIPELINE_PARAMETER_VALUES ,
1408
+ input_artifacts = _TEST_PIPELINE_INPUT_ARTIFACTS ,
1409
+ enable_caching = True ,
1410
+ )
1411
+
1412
+ pipeline_job_schedule = pipeline_job_schedules .PipelineJobSchedule (
1413
+ pipeline_job = job ,
1414
+ display_name = _TEST_PIPELINE_JOB_SCHEDULE_DISPLAY_NAME ,
1415
+ )
1416
+
1417
+ with pytest .raises (RuntimeError ) as e :
1418
+ pipeline_job_schedule .max_run_count
1419
+
1420
+ assert e .match (regexp = r"PipelineJobSchedule resource has not been created." )
1421
+
1422
+ pipeline_job_schedule .create (
1423
+ cron_expression = _TEST_PIPELINE_JOB_SCHEDULE_CRON_EXPRESSION ,
1424
+ max_concurrent_run_count = _TEST_PIPELINE_JOB_SCHEDULE_MAX_CONCURRENT_RUN_COUNT ,
1425
+ max_run_count = _TEST_PIPELINE_JOB_SCHEDULE_MAX_RUN_COUNT ,
1426
+ service_account = _TEST_SERVICE_ACCOUNT ,
1427
+ network = _TEST_NETWORK ,
1428
+ create_request_timeout = None ,
1429
+ )
1430
+
1431
+ pipeline_job_schedule .max_run_count
1432
+
1433
+ @pytest .mark .parametrize (
1434
+ "job_spec" ,
1435
+ [_TEST_PIPELINE_SPEC_JSON , _TEST_PIPELINE_SPEC_YAML , _TEST_PIPELINE_JOB ],
1436
+ )
1437
+ def test_get_cron_expression_before_create (
1438
+ self ,
1439
+ mock_schedule_service_create ,
1440
+ mock_schedule_service_get ,
1441
+ mock_schedule_bucket_exists ,
1442
+ job_spec ,
1443
+ mock_load_yaml_and_json ,
1444
+ ):
1445
+ """Gets the PipelineJobSchedule cron before creating.
1446
+
1447
+ Raises error because PipelineJobSchedule should be created first.
1448
+ """
1449
+ aiplatform .init (
1450
+ project = _TEST_PROJECT ,
1451
+ staging_bucket = _TEST_GCS_BUCKET_NAME ,
1452
+ location = _TEST_LOCATION ,
1453
+ credentials = _TEST_CREDENTIALS ,
1454
+ )
1455
+
1456
+ job = pipeline_jobs .PipelineJob (
1457
+ display_name = _TEST_PIPELINE_JOB_DISPLAY_NAME ,
1458
+ template_path = _TEST_TEMPLATE_PATH ,
1459
+ parameter_values = _TEST_PIPELINE_PARAMETER_VALUES ,
1460
+ input_artifacts = _TEST_PIPELINE_INPUT_ARTIFACTS ,
1461
+ enable_caching = True ,
1462
+ )
1463
+
1464
+ pipeline_job_schedule = pipeline_job_schedules .PipelineJobSchedule (
1465
+ pipeline_job = job ,
1466
+ display_name = _TEST_PIPELINE_JOB_SCHEDULE_DISPLAY_NAME ,
1467
+ )
1468
+
1469
+ with pytest .raises (RuntimeError ) as e :
1470
+ pipeline_job_schedule .cron_expression
1471
+
1472
+ assert e .match (regexp = r"PipelineJobSchedule resource has not been created." )
1473
+
1474
+ pipeline_job_schedule .create (
1475
+ cron_expression = _TEST_PIPELINE_JOB_SCHEDULE_CRON_EXPRESSION ,
1476
+ max_concurrent_run_count = _TEST_PIPELINE_JOB_SCHEDULE_MAX_CONCURRENT_RUN_COUNT ,
1477
+ max_run_count = _TEST_PIPELINE_JOB_SCHEDULE_MAX_RUN_COUNT ,
1478
+ service_account = _TEST_SERVICE_ACCOUNT ,
1479
+ network = _TEST_NETWORK ,
1480
+ create_request_timeout = None ,
1481
+ )
1482
+
1483
+ pipeline_job_schedule .cron_expression
1484
+
1485
+ @pytest .mark .parametrize (
1486
+ "job_spec" ,
1487
+ [_TEST_PIPELINE_SPEC_JSON , _TEST_PIPELINE_SPEC_YAML , _TEST_PIPELINE_JOB ],
1488
+ )
1489
+ def test_get_max_concurrent_run_count_before_create (
1490
+ self ,
1491
+ mock_schedule_service_create ,
1492
+ mock_schedule_service_get ,
1493
+ mock_schedule_bucket_exists ,
1494
+ job_spec ,
1495
+ mock_load_yaml_and_json ,
1496
+ ):
1497
+ """Gets the PipelineJobSchedule max_concurrent_run_count before creating.
1498
+
1499
+ Raises error because PipelineJobSchedule should be created first.
1500
+ """
1501
+ aiplatform .init (
1502
+ project = _TEST_PROJECT ,
1503
+ staging_bucket = _TEST_GCS_BUCKET_NAME ,
1504
+ location = _TEST_LOCATION ,
1505
+ credentials = _TEST_CREDENTIALS ,
1506
+ )
1507
+
1508
+ job = pipeline_jobs .PipelineJob (
1509
+ display_name = _TEST_PIPELINE_JOB_DISPLAY_NAME ,
1510
+ template_path = _TEST_TEMPLATE_PATH ,
1511
+ parameter_values = _TEST_PIPELINE_PARAMETER_VALUES ,
1512
+ input_artifacts = _TEST_PIPELINE_INPUT_ARTIFACTS ,
1513
+ enable_caching = True ,
1514
+ )
1515
+
1516
+ pipeline_job_schedule = pipeline_job_schedules .PipelineJobSchedule (
1517
+ pipeline_job = job ,
1518
+ display_name = _TEST_PIPELINE_JOB_SCHEDULE_DISPLAY_NAME ,
1519
+ )
1520
+
1521
+ with pytest .raises (RuntimeError ) as e :
1522
+ pipeline_job_schedule .max_concurrent_run_count
1523
+
1524
+ assert e .match (regexp = r"PipelineJobSchedule resource has not been created." )
1525
+
1526
+ pipeline_job_schedule .create (
1527
+ cron_expression = _TEST_PIPELINE_JOB_SCHEDULE_CRON_EXPRESSION ,
1528
+ max_concurrent_run_count = _TEST_PIPELINE_JOB_SCHEDULE_MAX_CONCURRENT_RUN_COUNT ,
1529
+ max_run_count = _TEST_PIPELINE_JOB_SCHEDULE_MAX_RUN_COUNT ,
1530
+ service_account = _TEST_SERVICE_ACCOUNT ,
1531
+ network = _TEST_NETWORK ,
1532
+ create_request_timeout = None ,
1533
+ )
1534
+
1535
+ pipeline_job_schedule .max_concurrent_run_count
1536
+
1537
+ @pytest .mark .parametrize (
1538
+ "job_spec" ,
1539
+ [_TEST_PIPELINE_SPEC_JSON , _TEST_PIPELINE_SPEC_YAML , _TEST_PIPELINE_JOB ],
1540
+ )
1541
+ def test_get_allow_queueing_before_create (
1542
+ self ,
1543
+ mock_schedule_service_create ,
1544
+ mock_schedule_service_get ,
1545
+ mock_schedule_bucket_exists ,
1546
+ job_spec ,
1547
+ mock_load_yaml_and_json ,
1548
+ ):
1549
+ """Gets the PipelineJobSchedule allow_queueing before creating.
1550
+
1551
+ Raises error because PipelineJobSchedule should be created first.
1552
+ """
1553
+ aiplatform .init (
1554
+ project = _TEST_PROJECT ,
1555
+ staging_bucket = _TEST_GCS_BUCKET_NAME ,
1556
+ location = _TEST_LOCATION ,
1557
+ credentials = _TEST_CREDENTIALS ,
1558
+ )
1559
+
1560
+ job = pipeline_jobs .PipelineJob (
1561
+ display_name = _TEST_PIPELINE_JOB_DISPLAY_NAME ,
1562
+ template_path = _TEST_TEMPLATE_PATH ,
1563
+ parameter_values = _TEST_PIPELINE_PARAMETER_VALUES ,
1564
+ input_artifacts = _TEST_PIPELINE_INPUT_ARTIFACTS ,
1565
+ enable_caching = True ,
1566
+ )
1567
+
1568
+ pipeline_job_schedule = pipeline_job_schedules .PipelineJobSchedule (
1569
+ pipeline_job = job ,
1570
+ display_name = _TEST_PIPELINE_JOB_SCHEDULE_DISPLAY_NAME ,
1571
+ )
1572
+
1573
+ with pytest .raises (RuntimeError ) as e :
1574
+ pipeline_job_schedule .allow_queueing
1575
+
1576
+ assert e .match (regexp = r"PipelineJobSchedule resource has not been created." )
1577
+
1578
+ pipeline_job_schedule .create (
1579
+ cron_expression = _TEST_PIPELINE_JOB_SCHEDULE_CRON_EXPRESSION ,
1580
+ max_concurrent_run_count = _TEST_PIPELINE_JOB_SCHEDULE_MAX_CONCURRENT_RUN_COUNT ,
1581
+ max_run_count = _TEST_PIPELINE_JOB_SCHEDULE_MAX_RUN_COUNT ,
1582
+ service_account = _TEST_SERVICE_ACCOUNT ,
1583
+ network = _TEST_NETWORK ,
1584
+ create_request_timeout = None ,
1585
+ )
1586
+
1587
+ pipeline_job_schedule .allow_queueing
0 commit comments