Repository: risingwavelabs/risingwave
File: src/meta/src/rpc/ddl_controller.rs (Rust)

Code before:
        let result = DdlController::resolve_stream_parallelism_inner(
            Some(NonZeroUsize::new(100).unwrap()),
            NonZeroUsize::new(256).unwrap(),
            Some(NonZeroUsize::new(4).unwrap()),
            &DefaultParallelism::Full,
            "default",
        )
        .unwrap();
        assert_eq!(result.get(), 100);
    }

    #[test]
    fn default_parallelism_can_exceed_available() {
        let result = DdlController::resolve_stream_parallelism_inner(
            None,
            NonZeroUsize::new(256).unwrap(),
            Some(NonZeroUsize::new(4).unwrap()),
            &DefaultParallelism::Default(NonZeroUsize::new(50).unwrap()),
            "default",
        )
        .unwrap();
        assert_eq!(result.get(), 50);
    }

    #[test]
    fn full_parallelism_respects_max_parallelism_cap() {
        let result = DdlController::resolve_stream_parallelism_inner(
            None,
            NonZeroUsize::new(6).unwrap(),
            Some(NonZeroUsize::new(10).unwrap()),
            &DefaultParallelism::Full,
            "default",
        )
        .unwrap();
        assert_eq!(result.get(), 6);
    }

    #[test]
    fn zero_available_returns_unavailable_error() {
        let result = DdlController::resolve_stream_parallelism_inner(
            None,
            NonZeroUsize::new(4).unwrap(),
            None,
            &DefaultParallelism::Full,
            "default",
        );
        assert!(matches!(
            result,
            Err(ref e) if matches!(e.inner(), MetaErrorInner::Unavailable(_))
        ));
    }

Review comment (suggestion):
[nitpick] Test name `full_parallelism_respects_max_parallelism_cap` could be clearer. Consider renaming to `test_full_parallelism_capped_by_max` to be more concise and follow common test naming conventions (starting with `test_`).
```suggestion
    fn test_full_parallelism_capped_by_max() {
```

Code after:
        let result = DdlController::resolve_stream_parallelism_inner(
            Some(NonZeroUsize::new(100).unwrap()),
            NonZeroUsize::new(256).unwrap(),
            Some(NonZeroUsize::new(4).unwrap()),
            &DefaultParallelism::Full,
            "default",
        )
        .unwrap();
        assert_eq!(result.get(), 100);
    }

    #[test]
    fn test_allows_default_parallelism_over_available() {
        let result = DdlController::resolve_stream_parallelism_inner(
            None,
            NonZeroUsize::new(256).unwrap(),
            Some(NonZeroUsize::new(4).unwrap()),
            &DefaultParallelism::Default(NonZeroUsize::new(50).unwrap()),
            "default",
        )
        .unwrap();
        assert_eq!(result.get(), 50);
    }

    #[test]
    fn test_full_parallelism_capped_by_max() {
        let result = DdlController::resolve_stream_parallelism_inner(
            None,
            NonZeroUsize::new(6).unwrap(),
            Some(NonZeroUsize::new(10).unwrap()),
            &DefaultParallelism::Full,
            "default",
        )
        .unwrap();
        assert_eq!(result.get(), 6);
    }

    #[test]
    fn test_no_available_slots_returns_error() {
        let result = DdlController::resolve_stream_parallelism_inner(
            None,
            NonZeroUsize::new(4).unwrap(),
            None,
            &DefaultParallelism::Full,
            "default",
        );
        assert!(matches!(
            result,
            Err(ref e) if matches!(e.inner(), MetaErrorInner::Unavailable(_))
        ));
    }