-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add codec group ptime config * update rexml --------- Co-authored-by: Denis Talakevich <senid231@gmail.com>
- Loading branch information
1 parent
f675c0a
commit e63282a
Showing
9 changed files
with
203 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
class CodecGroupPtime < ActiveRecord::Migration[7.0] | ||
def up | ||
execute %q{ | ||
alter table class4.codec_groups add ptime smallint; | ||
CREATE FUNCTION switch21.load_codec_groups() RETURNS TABLE(id integer, ptime smallint, codecs json) | ||
LANGUAGE plpgsql COST 10 | ||
AS $$ | ||
BEGIN | ||
RETURN QUERY | ||
SELECT | ||
cg.id, | ||
cg.ptime, | ||
json_agg(json_build_object( | ||
'id', c.id, | ||
'name', c.name, | ||
'priority', cgc.priority, | ||
'dynamic_payload_type', cgc.dynamic_payload_type, | ||
'format_parameters', cgc.format_parameters | ||
)) as codecs | ||
FROM class4.codec_groups cg | ||
LEFT JOIN class4.codec_group_codecs cgc ON cg.id = cgc.codec_group_id | ||
LEFT JOIN class4.codecs c ON cgc.codec_id=c.id | ||
GROUP BY cg.id; | ||
END; | ||
$$; | ||
CREATE OR REPLACE FUNCTION switch21.load_codecs() RETURNS TABLE(o_id integer, o_codec_group_id integer, o_codec_name character varying, o_priority integer, o_dynamic_payload_id integer, o_format_params character varying) | ||
LANGUAGE plpgsql COST 10 | ||
AS $$ | ||
BEGIN | ||
-- TODO: this function replaced by load_codec_groups and should be deleted in future | ||
RETURN | ||
QUERY SELECT | ||
cgc.id, | ||
cgc.codec_group_id, | ||
c.name , | ||
cgc.priority, | ||
cgc.dynamic_payload_type, | ||
cgc.format_parameters | ||
from class4.codec_group_codecs cgc | ||
JOIN class4.codecs c ON c.id=cgc.codec_id | ||
order by cgc.codec_group_id,cgc.priority desc ,c.name; | ||
END; | ||
$$; | ||
} | ||
end | ||
|
||
def down | ||
execute %q{ | ||
alter table class4.codec_groups drop column ptime; | ||
DROP FUNCTION switch21.load_codec_groups(); | ||
CREATE OR REPLACE FUNCTION switch21.load_codecs() RETURNS TABLE(o_id integer, o_codec_group_id integer, o_codec_name character varying, o_priority integer, o_dynamic_payload_id integer, o_format_params character varying) | ||
LANGUAGE plpgsql COST 10 | ||
AS $$ | ||
BEGIN | ||
RETURN | ||
QUERY SELECT | ||
cgc.id, | ||
cgc.codec_group_id, | ||
c.name , | ||
cgc.priority, | ||
cgc.dynamic_payload_type, | ||
cgc.format_parameters | ||
from class4.codec_group_codecs cgc | ||
JOIN class4.codecs c ON c.id=cgc.codec_id | ||
order by cgc.codec_group_id,cgc.priority desc ,c.name; | ||
END; | ||
$$; | ||
} | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe 'switch21.load_codec_groups' do | ||
subject do | ||
SqlCaller::Yeti.select_all(sql).map(&:deep_symbolize_keys) | ||
end | ||
|
||
let(:sql) do | ||
'SELECT * FROM switch21.load_codec_groups()' | ||
end | ||
let!(:codec_groups) do | ||
[ | ||
CodecGroup.find(1), | ||
create(:codec_group, ptime: nil), | ||
create(:codec_group, ptime: 20) | ||
] | ||
end | ||
|
||
it 'responds with correct codec_groups' do | ||
expect(subject).to match_array( | ||
codec_groups.map do |c| | ||
{ | ||
id: c.id, | ||
ptime: c.ptime, | ||
codecs: a_kind_of(String) | ||
} | ||
end | ||
) | ||
end | ||
|
||
it 'responds with correct codecs inside codec_groups', :aggregate_failures do | ||
subject.each do |row| | ||
codec_group = codec_groups.detect { |c| c.id == row[:id] } | ||
actual_codecs = JSON.parse(row[:codecs], symbolize_names: true) | ||
expect(actual_codecs).to match_array( | ||
codec_group.codec_group_codecs.map do |codec_group_codec| | ||
codec = codec_group_codec.codec | ||
{ | ||
id: codec.id, | ||
name: codec.name, | ||
priority: codec_group_codec.priority, | ||
dynamic_payload_type: codec_group_codec.dynamic_payload_type, | ||
format_parameters: codec_group_codec.format_parameters | ||
} | ||
end | ||
) | ||
end | ||
end | ||
end |