Skip to content

Commit c90e8cc

Browse files
Add some testcases and missing ASF headers for new scheduler (#5243)
* Add some testcases and missing ASF headers for new scheduler * Reset stream after each test * Wait more time * Update msg start time to ensure it's not stale * Make MemoryQueueFlowTests stable * Ignore warmUp msg immediately * Use retry to replace sleep * Add missing config * Fix configuration error
1 parent edc484b commit c90e8cc

File tree

13 files changed

+676
-48
lines changed

13 files changed

+676
-48
lines changed

core/controller/src/main/resources/reference.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ whisk {
3131
timeout-addon = 1m
3232

3333
fpc {
34-
use-perMin-throttles = false
34+
use-per-min-throttles = false
3535
}
3636
}
3737
controller {

core/controller/src/main/scala/org/apache/openwhisk/core/loadBalancer/FPCPoolBalancer.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
118
package org.apache.openwhisk.core.loadBalancer
219

320
import java.nio.charset.StandardCharsets

core/scheduler/src/main/scala/org/apache/openwhisk/core/scheduler/queue/SchedulingDecisionMaker.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
118
package org.apache.openwhisk.core.scheduler.queue
219

320
import akka.actor.{Actor, ActorSystem, Props}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.openwhisk.core.controller.test
19+
20+
import org.apache.openwhisk.common.TransactionId
21+
import org.apache.openwhisk.core.controller.RejectRequest
22+
import org.apache.openwhisk.core.entitlement.{EntitlementProvider, FPCEntitlementProvider, Privilege, Resource}
23+
import org.apache.openwhisk.core.entitlement.Privilege.{ACTIVATE, DELETE, PUT, READ, REJECT}
24+
import org.apache.openwhisk.core.entity.{EntityName, EntityPath, FullyQualifiedEntityName}
25+
import org.apache.openwhisk.core.loadBalancer.LoadBalancer
26+
import org.junit.runner.RunWith
27+
import org.scalamock.scalatest.MockFactory
28+
import org.scalatest.concurrent.ScalaFutures
29+
import org.scalatest.junit.JUnitRunner
30+
31+
@RunWith(classOf[JUnitRunner])
32+
class FPCEntitlementProviderTests extends ControllerTestCommon with ScalaFutures with MockFactory {
33+
34+
implicit val transactionId = TransactionId.testing
35+
36+
it should "get throttle flag from loadBalancer" in {
37+
val someUser = WhiskAuthHelpers.newIdentity()
38+
val action = FullyQualifiedEntityName(EntityPath("testns"), EntityName("action"))
39+
val loadBalancer = mock[LoadBalancer]
40+
(loadBalancer
41+
.checkThrottle(_: EntityPath, _: String))
42+
.expects(someUser.namespace.name.toPath, action.fullPath.asString)
43+
.returning(true)
44+
val resources = Set(Resource(action.path, ACTIONS, Some(action.name.name)))
45+
46+
val entitlementProvider: EntitlementProvider = new FPCEntitlementProvider(whiskConfig, loadBalancer, instance)
47+
entitlementProvider.checkThrottles(someUser, ACTIVATE, resources).failed.futureValue shouldBe a[RejectRequest]
48+
49+
Seq[Privilege](READ, PUT, DELETE, REJECT).foreach(OP => {
50+
noException shouldBe thrownBy(entitlementProvider.checkThrottles(someUser, OP, resources).futureValue)
51+
})
52+
53+
val action2 = FullyQualifiedEntityName(EntityPath("testns2"), EntityName("action2"))
54+
val resources2 = Set(Resource(action2.path, ACTIONS, Some(action2.name.name)))
55+
(loadBalancer
56+
.checkThrottle(_: EntityPath, _: String))
57+
.expects(someUser.namespace.name.toPath, action2.fullPath.asString)
58+
.returning(false)
59+
noException shouldBe thrownBy(entitlementProvider.checkThrottles(someUser, ACTIVATE, resources2).futureValue)
60+
}
61+
}

tests/src/test/scala/org/apache/openwhisk/core/loadBalancer/test/FPCPoolBalancerTests.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
118
package org.apache.openwhisk.core.loadBalancer.test
219

320
import akka.actor.{ActorRef, ActorRefFactory, ActorSystem, Props}

0 commit comments

Comments
 (0)